method TcpStream.readText
Like read, for UTF-8 text; bytes that are not valid UTF-8 give ProtocolError.
Example:
use std.net { SocketAddr, TcpListener, TcpStream, IpAddr }
fn main() -> () | NetError | ParseError io, net {
let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
defer l.close()?
let c = TcpStream.connect(l.local, 2s)?
defer c.close()?
let s = l.accept(3s)?
defer s.close()?
c.writeText("héllo")?
print(s.readText(64)?)
}Вывод
héllo
pub(api) fn readText(max: usize, timeout: Duration? = none) -> str | NetError netС версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
max | usize |
timeout | Duration? = none |
Возвращает
str
Ошибки
NetError- those of `read`; `ProtocolError` when the bytes are not valid UTF-8.
Эффекты
net
Определено в: std/net/net.oxl:580