meli/melib/src/lib.rs

176 lines
5.2 KiB
Rust
Raw Normal View History

/*
* meli - lib.rs
*
* Copyright 2017 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
2019-05-01 19:20:33 +03:00
#[macro_use]
pub mod dbg {
2019-05-13 22:05:00 +03:00
#[allow(clippy::redundant_closure)]
2019-05-01 19:20:33 +03:00
#[macro_export]
macro_rules! debug {
2019-05-07 01:54:20 +03:00
($val:literal) => {
2019-05-12 17:37:07 +03:00
{
if cfg!(feature="debug-tracing") {
2019-05-07 01:54:20 +03:00
eprint!(
"[{:?}] {}:{}_{}: ",
std::thread::current()
.name()
2019-06-18 21:13:58 +03:00
.map(std::string::ToString::to_string)
2019-05-07 01:54:20 +03:00
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
file!(),
line!(),
column!()
);
eprintln!($val);
}
2019-05-12 17:37:07 +03:00
$val
}
2019-05-07 01:54:20 +03:00
};
2019-05-01 19:20:33 +03:00
($val:expr) => {
if cfg!(feature="debug-tracing") {
let stringify = stringify!($val);
2019-07-09 13:05:11 +03:00
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
eprint!(
"[{:?}] {}:{}_{}: ",
std::thread::current()
.name()
.map(std::string::ToString::to_string)
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
file!(),
line!(),
column!()
);
eprintln!("{} = {:?}", stringify, tmp);
2019-07-09 13:05:11 +03:00
tmp
}
}
} else {
$val
2019-05-12 17:37:07 +03:00
}
2019-05-01 19:20:33 +03:00
};
($fmt:literal, $($arg:tt)*) => {
if cfg!(feature="debug-tracing") {
2019-05-01 19:20:33 +03:00
eprint!(
"[{:?}] {}:{}_{}: ",
std::thread::current()
.name()
2019-06-18 21:13:58 +03:00
.map(std::string::ToString::to_string)
2019-05-01 19:20:33 +03:00
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
file!(),
line!(),
column!()
);
eprintln!($fmt, $($arg)*);
}
};
}
}
#[cfg(feature = "unicode_algorithms")]
2019-07-22 15:14:39 +03:00
extern crate text_processing;
2019-09-15 20:39:16 +03:00
#[macro_use]
mod logging;
pub use self::logging::LoggingLevel::*;
pub use self::logging::*;
2019-03-14 12:19:25 +02:00
pub mod addressbook;
2019-04-04 14:21:52 +03:00
pub mod async_workers;
2019-05-26 15:54:45 +03:00
pub mod backends;
mod collection;
pub mod conf;
2019-05-26 15:54:45 +03:00
pub mod email;
pub mod error;
2018-07-27 21:37:56 +03:00
pub mod mailbox;
2019-05-26 15:54:45 +03:00
pub mod thread;
pub use crate::email::*;
2019-06-18 21:13:58 +03:00
pub use crate::thread::*;
2019-05-26 21:34:34 +03:00
mod structs;
pub use self::structs::*;
2019-11-07 09:46:09 +02:00
pub mod parsec;
#[macro_use]
extern crate serde_derive;
/* parser */
#[macro_use]
extern crate nom;
extern crate chrono;
2018-07-24 20:20:32 +03:00
extern crate data_encoding;
2018-07-27 21:37:56 +03:00
extern crate encoding;
#[macro_use]
extern crate bitflags;
2019-02-15 09:06:42 +02:00
extern crate fnv;
2019-03-14 12:19:25 +02:00
extern crate uuid;
2017-09-28 18:06:35 +03:00
2019-06-18 21:13:58 +03:00
pub use crate::conf::*;
pub use crate::mailbox::*;
2017-09-28 18:06:35 +03:00
pub use crate::backends::{Backends, RefreshEvent, RefreshEventConsumer, SpecialUseMailbox};
2019-06-18 21:13:58 +03:00
pub use crate::email::{Envelope, Flag};
pub use crate::error::{MeliError, Result};
2019-02-15 09:06:42 +02:00
2019-06-18 21:13:58 +03:00
pub use crate::addressbook::*;
pub use shellexpand::ShellExpandTrait;
pub mod shellexpand {
use std::path::*;
pub trait ShellExpandTrait {
fn expand(&self) -> PathBuf;
}
impl ShellExpandTrait for Path {
fn expand(&self) -> PathBuf {
let mut ret = PathBuf::new();
for c in self.components() {
let c_to_str = c.as_os_str().to_str();
match c_to_str {
Some("~") => {
if let Some(home_dir) = std::env::var("HOME").ok() {
ret.push(home_dir)
} else {
return PathBuf::new();
}
}
Some(var) if var.starts_with("$") => {
let env_name = var.split_at(1).1;
if env_name.chars().all(char::is_uppercase) {
ret.push(std::env::var(env_name).unwrap_or(String::new()));
} else {
ret.push(c);
}
}
Some(_) => {
ret.push(c);
}
None => {
/* path is invalid */
return PathBuf::new();
}
}
}
ret
}
}
}