Move the Date struct into types and implement a get_property_numeric.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::elisp_fact::GetElispFact;
|
||||
use super::sexp::Token;
|
||||
use crate::compare::sexp::unquote;
|
||||
@@ -234,3 +236,23 @@ pub(crate) fn get_property_boolean<'b, 's, 'x>(
|
||||
.unwrap_or("nil")
|
||||
!= "nil")
|
||||
}
|
||||
|
||||
/// Get a named property containing an unquoted numeric value.
|
||||
///
|
||||
/// Returns None if key is not found.
|
||||
pub(crate) fn get_property_numeric<'b, 's, 'x, N: FromStr>(
|
||||
emacs: &'b Token<'s>,
|
||||
key: &'x str,
|
||||
) -> Result<Option<N>, Box<dyn std::error::Error>>
|
||||
where
|
||||
<N as FromStr>::Err: std::error::Error,
|
||||
<N as FromStr>::Err: 'static,
|
||||
{
|
||||
let foo = get_property(emacs, key)?
|
||||
.map(Token::as_atom)
|
||||
.map_or(Ok(None), |r| r.map(Some))?;
|
||||
let bar = foo
|
||||
.map(|val| val.parse::<N>())
|
||||
.map_or(Ok(None), |r| r.map(Some))?;
|
||||
Ok(bar)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user