Function in io::file coil-stdlib

read_text

fn read_text(string path) -> Result<string, IoError>
Import
use io::file::{read_text};
Source: src/io/file.hy

Reads the whole file at path as UTF-8 text.

Needs --allow-read.

Parameters#

NameType
pathstring

Returns#

Result<string, IoError>

Errors#

IoError::NotFound when the file does not exist and IoError::InvalidInput when it is not valid UTF-8.

Examples#

use io::file::{read_text};
use io::sync::{println};

fn main() {
    let config = read_text("config.toml")?;
    println(config)?;
}

See also#

  • read_bytes: Reads the whole file at path.
  • write_bytes: Replaces the contents of the file at path with buf, creating it if needed, and returns the number of bytes written.
  • write_text: Replaces the contents of the file at path with text, creating it if needed, and returns the number of bytes written.
  • append_bytes: Appends buf to the file at path, creating it if needed.
  • append_text: Appends text to the file at path, creating it if needed.
↑ ↓ navigate ↵ open