pub struct SafeLocale { /* private fields */ }Expand description
RAII guard temporarily switching the numeric locale to "C"
(igraph_enter_safelocale / igraph_exit_safelocale).
igraph’s readers and writers need a locale with a decimal point. While
the guard is alive the "C" numeric locale is in effect for the current
thread (on platforms without per-thread locales igraph falls back to the
process-wide setlocale, which is not thread safe); dropping it restores
the previous locale. Rust programs start in the "C" locale, so this is
only needed when some other code changed it.
The guard is neither Send nor Sync: it must be dropped on the
thread that created it. Nested guards restore their locales correctly
when dropped in reverse order of creation (as scopes do).
Binds igraph_enter_safelocale
and igraph_exit_safelocale.
use igraph::{foreign::SafeLocale, prelude::*};
let g = Graph::from_edges(&[(0, 1)], 2, true).unwrap();
let text = {
let _locale = SafeLocale::enter().unwrap();
g.write_graph_dimacs_flow_to_string(0, 1, &[0.5]).unwrap()
}; // previous locale restored here
assert!(text.ends_with("a 1 2 0.5\n"));Implementations§
Source§impl SafeLocale
impl SafeLocale
Sourcepub fn enter() -> Result<Self>
pub fn enter() -> Result<Self>
Switches the current thread to the "C" numeric locale until the
returned guard is dropped.
§Errors
ErrorKind::Failure if the "C" locale can’t be created.