Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

OptionWriter

Ivan Semenkov edited this page Feb 4, 2021 · 1 revision

Table of contents

About

It is writer for configuration option.

pub struct OptionWriter

delete

Delete current config element.

pub fn delete(&self) -> Result<()>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("group") {
  Some(group) => {
  
    if !group.delete().is_ok() {
    
    }
  },
  None => { /* ... */ }
}

create_section

Create new group section.

pub fn create_section<S>(&self, path : S) -> Option<OptionWriter> 
  where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("root.group") {
  Some(s) => { /* ... */ },
  None => { /* ... */ }
}

create_array

Create new array group section.

pub fn create_array<S>(&self, path : S) -> Option<CollectionWriter> 
  where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
let group = cfg.create_section("group").unwrap();
match group.create_array("array") {
  Some(s) => { /* ... */ },
  None => { /* ... */ }
}

create_list

Create new list group section.

pub fn create_list<S>(&self, path : S) -> Option<CollectionWriter> 
  where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
let group = cfg.create_section("group").unwrap();
match group.create_list("root.list") {
  Some(s) => { /* ... */ },
  None => { /* ... */ }
}

write_int32

Add new integer value to current group.

pub fn write_int32<S>(&self, name : S, value : i32) -> 
  Option<OptionWriter> where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("section") {
  Some(s) => { 
    s.write_int32("ival", 321); 
  },
  None => { /* ... */ }
}

write_int64

Add new int64 value to current group.

pub fn write_int64<S>(&self, name : S, value : i64) -> 
  Option<OptionWriter> where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("section") {
  Some(s) => { 
    s.write_int64("ival", 321000); 
  },
  None => { /* ... */ }
}

write_float64

Add new float value to current group.

pub fn write_float64<S>(&self, name : S, value : f64) -> 
  Option<OptionWriter> where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("section") {
  Some(s) => { 
    s.write_float64("ival", 321.001); 
  },
  None => { /* ... */ }
}

write_bool

Add new boolean value to current group.

pub fn write_bool<S>(&self, name : S, value : bool) -> 
  Option<OptionWriter> where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("section") {
  Some(s) => { 
    s.write_bool("ival", false); 
  },
  None => { /* ... */ }
}

write_string

Add new string value to current group.

pub fn write_string<S>(&self, name : S, value : S) -> 
  Option<OptionWriter> where S: Into<String>
Example
use librustconfig::config::Config;

let cfg = Config::new();
match cfg.create_section("section") {
  Some(s) => { 
    s.write_string("ival", "test string"); 
  },
  None => { /* ... */ }
}