Skip to main content

SafeLocale

Struct SafeLocale 

Source
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

Source

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.

Trait Implementations§

Source§

impl Debug for SafeLocale

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for SafeLocale

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.