[][src]Struct libzettels::Config

pub struct Config {
    pub rootdir: PathBuf,
    pub indexfile: PathBuf,
    pub indexingmethod: IndexingMethod,
    pub sequencestart: SequenceStart,
    pub ignorefile: PathBuf,
}

Config represents the user's configuration. See "Fields" for details of what each value represents. It bundles user specified settings from a configuration file and can be serialized to and deserialized from such a file.

Config derives Serialize and Deserialize via serde and can thus be serialized and deserialized to any format supported by serde. See README.md for details.

The included methods from_file and to_file (de)serialize from/to YAML.

Example

Minimal Configuration file (YAML)

---
rootdir: examples/Zettelkasten
indexfile: examples/index.yaml

Full Configuration file (YAML)

---
rootdir: examples/Zettelkasten
indexfile: examples/index.yaml
indexingmethod: Grep
sequencestart: Keyword
ignorefile: .gitignore

Fields

rootdir: PathBuf

The path to the root directory of the Zettelkasten, i.e. the directory containing the zettel files.

indexfile: PathBuf

The path to the index file.

indexingmethod: IndexingMethod

Optional: Indexing method

Default: IndexingMethod::Native

sequencestart: SequenceStart

Optional: Criteria how libzettels identifies a Zettel as the start of a sequence.

Default: SequenceStart::Keyword

ignorefile: PathBuf

Optional: A file specifying patterns to be ignored by the as gitignore files.

Default: By default, it is .gitignore (because you might manage your Zettelkasten with git). But in case you want different ignore-patterns for git and your Zettelkasten, you can specify an alternative file, here (e.g. .zettelsignore).

Implementations

impl Config[src]

pub fn new<T: AsRef<Path>>(rootdir: T, indexfile: T) -> Config[src]

Creates a new Config by specifying a root directory and a file name for the index file as strings.

Example

let cfg = Config::new("examples/Zettelkasten", 
                      "examples/index.yaml");

assert_eq!(&cfg.rootdir, Path::new("examples/Zettelkasten"));
assert_eq!(&cfg.indexfile, Path::new("examples/index.yaml"));
assert_eq!(&cfg.ignorefile, Path::new(".gitignore"));

pub fn from_file<P: AsRef<Path>>(configfile: P) -> Result<Config, Error>[src]

Creates a new Config by deserializing it from a YAML-file.

Example

let cfg = Config::from_file(Path::new("examples/zettels-examples.cfg.yaml"))?;

Errors

pub fn to_file<P: AsRef<Path>>(&self, configfile: P) -> Result<(), Error>[src]

Serializes the Config self to a YAML-file.

Example

let cfg = Config::new("examples/Zettelkasten", 
                      "examples/index.yaml");
match cfg.to_file(Path::new("examples/zettels-examples.cfg.yaml")) {
   Ok(_) => println!("Saved config."), 
   Err(error) => panic!("Failed to write config to file. {}", error),
};

Errors

Trait Implementations

impl Debug for Config[src]

impl<'de> Deserialize<'de> for Config[src]

impl PartialEq<Config> for Config[src]

impl Serialize for Config[src]

impl StructuralPartialEq for Config[src]

Auto Trait Implementations

impl RefUnwindSafe for Config

impl Send for Config

impl Sync for Config

impl Unpin for Config

impl UnwindSafe for Config

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.