Struct Log

Source
pub struct Log { /* private fields */ }
Expand description

The main struct for the custom log

§Example

To use the custom log, you need to use 3 steps. At first you will create a new Log. (You can also create more than one log for different usage.)

Just to remind, dont forget to import the custom

use log_file::custom::*;

Then go on with the creating the Log:

    // create Log
    let mut log = Log::new(true, ':');

The second step is to use it. In the following I just will show the different options:

// with context as String
log.add("Titel 1",String::from("Context 1"));
 
// with context as &str
log.add_str("Titel 2","Context 2");

If that is done, you can finaly save the log in the end. Here an example for this step:

// save log
log.save("log.txt");

And now you are done. Now, every time you run your project, the new log will overwrite the existing one, if the file name dosn’t change.

Implementations§

Source§

impl Log

Source

pub fn new(time_stamp_on: bool, seperate: char) -> Log

create a new log

§Example
let example = Log::new(true, ':'));
Source

pub fn add(&mut self, titel: &str, context: String)

adding an element to this log with context as String

§Example
let mut example = Log::new(true, ':'));
example.add("Test",String::from("Hello, world!"));
Source

pub fn add_str(&mut self, titel: &str, context: &str)

adding an element to this log with context as &str

§Example
let mut example = Log::new(true, ':'));
example.add_str("Test","Hello, world!");
Source

pub fn save(&self, file_name: &str)

saves the log in file_name

Creates file if it does not exist and overwrites it if it does exist.

§Note

You have to give the whole file name as parameter. For example foo.txt. If you just give foo as file name, it will create a file without file type.

§Example
use log_file::default_code::Log;
 
fn main() {
    let example = Log::new(true, String::from(":"));
    example.save("foo.txt");
}
Source

pub fn to_string(&self) -> String

converts this struct Log

§Example
use log_file::default_code::Log;
 
fn main() {
    let example = Log::new(true, String::from(":"));
    println!("{}",example.to_string());
}

output:

 

Trait Implementations§

Source§

impl Clone for Log

Source§

fn clone(&self) -> Log

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Log

§

impl RefUnwindSafe for Log

§

impl Send for Log

§

impl Sync for Log

§

impl Unpin for Log

§

impl UnwindSafe for Log

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.