method Response.text
The body as UTF-8 text.
Example:
use std.http { Response, Header }
fn sample() -> Response {
Response{
status: 200, reason: "OK", version: "1.1",
headers: [Header{ name: "Content-Type", value: "text/plain" }, Header{ name: "Set-Cookie", value: "a=1" }, Header{ name: "Set-Cookie", value: "b=2" }],
body: Utf8.encode("hello"), url: "http://example.org/", reused: false, redirects: 0
}
}
fn main() io {
match sample().text() {
str t => print(t)
DecodeError _ => print("not text")
}
}Вывод
hello
pub(api) fn text() -> str | DecodeErrorСложность. O(n) in the size of the body.
С версии. 1.0.0-beta
Возвращает
str
Ошибки
DecodeError@error- `DecodeError` when the body is not valid UTF-8.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/http/http.oxl:314