1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: change optional to result of io (#16075)

This commit is contained in:
yuyi
2022-10-16 14:28:57 +08:00
committed by GitHub
parent 6e46933c55
commit f6844e9766
187 changed files with 1885 additions and 1874 deletions

View File

@@ -44,15 +44,15 @@ fn new_ip(port u16, addr [4]u8) Addr {
return a
}
fn temp_unix() ?Addr {
fn temp_unix() !Addr {
// create a temp file to get a filename
// close it
// remove it
// then reuse the filename
mut file, filename := util.temp_file()?
mut file, filename := util.temp_file()!
file.close()
os.rm(filename)?
addrs := resolve_addrs(filename, .unix, .udp)?
os.rm(filename)!
addrs := resolve_addrs(filename, .unix, .udp)!
return addrs[0]
}
@@ -114,7 +114,7 @@ fn (a Addr) len() u32 {
}
}
pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ?[]Addr {
pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ![]Addr {
match family {
.ip, .ip6, .unspec {
return resolve_ipaddrs(addr, family, @type)
@@ -143,9 +143,9 @@ pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ?[]Addr {
}
}
pub fn resolve_addrs_fuzzy(addr string, @type SocketType) ?[]Addr {
pub fn resolve_addrs_fuzzy(addr string, @type SocketType) ![]Addr {
if addr.len == 0 {
return none
return error('none')
}
// Use a small heuristic to figure out what address family this is
@@ -160,8 +160,8 @@ pub fn resolve_addrs_fuzzy(addr string, @type SocketType) ?[]Addr {
return resolve_addrs(addr, .unix, @type)
}
pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
address, port := split_address(addr)?
pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ![]Addr {
address, port := split_address(addr)!
if addr[0] == `:` {
match family {
@@ -191,10 +191,10 @@ pub fn resolve_ipaddrs(addr string, family AddrFamily, typ SocketType) ?[]Addr {
// This might look silly but is recommended by MSDN
$if windows {
socket_error(0 - C.getaddrinfo(&char(address.str), &char(sport.str), &hints, &results))?
socket_error(0 - C.getaddrinfo(&char(address.str), &char(sport.str), &hints, &results))!
} $else {
x := C.getaddrinfo(&char(address.str), &char(sport.str), &hints, &results)
wrap_error(x)?
wrap_error(x)!
}
defer {