Function in io::file coil-stdlib

write_text

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

Replaces the contents of the file at path with text, creating it if needed, and returns the number of bytes written.

Needs --allow-write.

Parameters#

NameType
pathstring
textstring

Returns#

Result<int, IoError>

Examples#

use io::file::{write_text, read_text};

fn main() {
    write_text("greeting.txt", "hello\n")?;
    let back = read_text("greeting.txt")?;
}

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.
  • read_text: Reads the whole file at path as UTF-8 text.
  • 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