txt_writer

Crates.iotxt_writer
lib.rstxt_writer
version0.1.4
sourcesrc
created_at2022-09-01 21:26:06.606781
updated_at2022-09-12 21:29:39.524181
descriptionEasier and faster way to write txt files in rust
homepagehttps://carghaiwebsite.web.app/#/
repositoryhttps://github.com/carghai/txt_writer
max_upload_size
id657030
size9,242
Ekam (ekam-g)

documentation

README

Why use this package?

This package allows you to write and read txt file with one line of code, rather then having to waste time and write 10-50 lines of code!

How do I read files?

There are two ways to read a file. One reads a file line by line(read), one reads it as a string (read_one).

Line by line version

fn main() {
    let data = txt_writer::ReadData {}
            .read("path to your txt".to_string())
            .expect("failed when reading");
        for x in data {
            println!("{}", x);
        }
}

All in one version

fn main() {
 let data = txt_writer::ReadData {}
        .read_one("path to your txt".to_string())
        .expect("failed when reading");
    println!("{}", data);
}

How do I write data?

There are 2 ways to write data. If you want to create a txt OR overwrite data use this.

use this one if you want to pass a String value

fn main() {
    txt_writer::WriteData {}
        .replace(
            "what you want to write to txt".to_string(),
            "path to your txt".to_string(),
        )
        .expect("failed when writing");
}

Use this one if you want to add data to an existing txt.

NOTE THIS FUNCTION WILL RETURN AN ERROR IF THE TXT DOES NOT EXIST

fn main(){
    txt_writer::WriteData {}
            .add(
                "what you want to write to txt".to_string(),
                "path to your txt".to_string(),
            )
            .expect("failed when writing");
}

Example

use txt_writer;

fn main() {
    txt_writer::WriteData {}
        .replace(
            &"what you want to write to txt".to_string(),
            "src/data.txt".to_string(),
        )
        .expect("failed when writing");

    txt_writer::WriteData {}
        .add(
            &"what you want to write to txt".to_string(),
            "src/data.txt".to_string(),
        )
        .expect("failed when writing");

    let data = txt_writer::ReadData {}
        .read("src/data.txt".to_string())
        .expect("failed when reading");
    for x in data {
        println!("{}", x);
    }

    let data = txt_writer::ReadData {}
        .read_one("src/data.txt".to_string())
        .expect("failed when reading");
    println!("{}", data);
}
Commit count: 16

cargo fmt