stable-osstring-encoding 2.1.0

Converts OsString (and more) to and from raw data with an encoding that will not change based on the compiler version.
Documentation
use crate::{EncodingWidth, StableOsString};
use std::borrow::Cow;
#[cfg(doc)]
use std::ffi::{OsStr, OsString};



/// Converts a type to an encoding that is stable across rust compiler versions
pub trait ToRawStableEncoding {
	/// Converts a type to an encoding that is stable across rust compiler versions
	#[must_use]
	fn to_raw_stable_encoding(&self) -> Vec<EncodingWidth>;
}

/// Converts an owned type to an encoding that is stable across rust compiler versions, bypassing data copies if possible
pub trait IntoRawStableEncoding {
	/// Converts an owned type to an encoding that is stable across rust compiler versions, bypassing data copies if possible
	#[must_use]
	fn into_raw_stable_encoding(self) -> Vec<EncodingWidth>;
}

/// Crates an [`OsString`] from an encoding that is stable across rust compiler versions, bypassing data copies if possible
pub trait FromRawStableEncoding {
	/// Converts an [`OsString`] from an encoding that is stable across rust compiler versions, bypassing data copies if possible
	///
	/// This takes `Into<Cow<[EncodingWidth]>>` so that either a slice can be passed (which always allocates and copies data) or a vec can be passed (which might be able to skip allocating and copying data)
	///
	/// # Safety
	///
	/// The given bytes must be compatible with the underlying of the platform's [`OsStr`] encoding (reminder: this crate only make it safe to pass data between different rust versions)
	#[must_use]
	unsafe fn from_raw_stable_encoding<'a>(encoded: impl Into<Cow<'a, [EncodingWidth]>>) -> Self;
}



/// Converts a type to an encoding that is stable across rust compiler versions
pub trait ToStableEncoding {
	/// Converts a type to an encoding that is stable across rust compiler versions
	#[must_use]
	fn to_stable_encoding(&self) -> StableOsString;
}

/// Converts an owned type to an encoding that is stable across rust compiler versions, bypassing data copies if possible
pub trait IntoStableEncoding {
	/// Converts an owned type to an encoding that is stable across rust compiler versions, bypassing data copies if possible
	#[must_use]
	fn into_stable_encoding(self) -> StableOsString;
}