1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00
actix-extras/actix-settings/src/parse.rs
dependabot[bot] 257871ca7a
Update toml requirement from 0.5 to 0.8 (#335)
* Update toml requirement from 0.5 to 0.8

Updates the requirements on [toml](https://github.com/toml-rs/toml) to permit the latest version.
- [Commits](https://github.com/toml-rs/toml/compare/toml_datetime-v0.5.0...toml-v0.8.0)

---
updated-dependencies:
- dependency-name: toml
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* docs(settings): update changelog

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rob Ede <robjtede@icloud.com>
2023-09-15 23:59:19 +00:00

41 lines
989 B
Rust

use std::{path::PathBuf, str::FromStr};
use crate::Error;
/// A specialized `FromStr` trait that returns [`Error`] errors
pub trait Parse: Sized {
/// Parse `Self` from `string`.
fn parse(string: &str) -> Result<Self, Error>;
}
impl Parse for bool {
fn parse(string: &str) -> Result<Self, Error> {
Self::from_str(string).map_err(Error::from)
}
}
macro_rules! impl_parse_for_int_type {
($($int_type:ty),+ $(,)?) => {
$(
impl Parse for $int_type {
fn parse(string: &str) -> Result<Self, Error> {
Self::from_str(string).map_err(Error::from)
}
}
)+
}
}
impl_parse_for_int_type![i8, i16, i32, i64, i128, u8, u16, u32, u64, u128];
impl Parse for String {
fn parse(string: &str) -> Result<Self, Error> {
Ok(string.to_string())
}
}
impl Parse for PathBuf {
fn parse(string: &str) -> Result<Self, Error> {
Ok(PathBuf::from(string))
}
}