pub struct ImportFlags(/* private fields */);Implementations§
Source§impl ImportFlags
impl ImportFlags
Source§impl ImportFlags
impl ImportFlags
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Get a flags value with all bits unset.
Examples found in repository?
66fn main() -> Result<(), Box<dyn std::error::Error>> {
67 println!("Creating WSL API instance...");
68
69 let wsl = match Wsl2::new() {
70 Ok(wsl) => {
71 println!("WSL API instance created successfully");
72 wsl
73 }
74 Err(e) if e.kind() == Some(WslErrorKind::UnsupportedOperatingSystem) => {
75 eprintln!("WSL is not installed or enabled on this operating system");
76 return Ok(());
77 }
78 Err(e) if e.kind() == Some(WslErrorKind::UnsupportedWslVersion) => {
79 eprintln!("WSL version is not supported");
80 return Ok(());
81 }
82 Err(e) => {
83 eprintln!("Failed to create WSL1/2 API instance: {:?}", e);
84 eprintln!("This may be due to WSL2 not being installed or enabled");
85 return Err(e.into());
86 }
87 };
88
89 println!("Getting default distribution...");
90 let default_distro = match wsl.get_default_distribution() {
91 Ok(distro) => {
92 println!("Successfully retrieved default distribution: {:?}", distro);
93 distro
94 }
95 Err(e) => {
96 eprintln!("Failed to get default distribution: {:?}", e);
97 return Err(e.into());
98 }
99 };
100
101 println!("Enumerating distributions...");
102 match wsl.enumerate_distributions() {
103 Ok(distros) => println!("Successfully enumerated distributions: {:?}", distros),
104 Err(e) => {
105 eprintln!("Failed to enumerate distributions: {:?}", e);
106 return Err(e.into());
107 }
108 }
109
110 println!("Exporting distribution...");
111 let file = std::fs::File::create("distro.tar.gz").unwrap();
112 let (r, w) = std::io::pipe().unwrap();
113 let result = wsl.export_distribution(default_distro, file, w, ExportFlags::empty());
114 // Keep the read end alive until after the export completes
115 drop(r);
116 match result {
117 Ok(_) => println!("Successfully exported distribution"),
118 Err(e) => {
119 eprintln!("Failed to export distribution: {:?}", e);
120 return Err(e.into());
121 }
122 }
123
124 let file = std::fs::File::open("distro.tar.gz").unwrap();
125
126 println!("Registering distribution...");
127 let (r, w) = std::io::pipe().unwrap();
128 let result = wsl.register_distribution("test", Version::WSL2, file, w, ImportFlags::empty());
129 let guid_copy = match result {
130 Ok((guid, name)) => {
131 println!("Successfully registered distribution: {:?} {}", guid, name);
132 guid
133 }
134 Err(e) => {
135 eprintln!("Failed to register distribution: {:?}", e);
136 return Err(e.into());
137 }
138 };
139 drop(r);
140
141 println!("Setting version...");
142 let result = wsl.set_version(guid_copy, Version::WSL1, std::io::stderr());
143 match result {
144 Ok(_) => println!("Successfully set version"),
145 Err(e) => {
146 eprintln!("Failed to set version: {:?}", e);
147 return Err(e.into());
148 }
149 }
150
151 println!("Enumerating distributions...");
152 match wsl.enumerate_distributions() {
153 Ok(distros) => println!("Successfully enumerated distributions: {:?}", distros),
154 Err(e) => {
155 eprintln!("Failed to enumerate distributions: {:?}", e);
156 return Err(e.into());
157 }
158 }
159
160 run_command(&wsl, default_distro)?;
161
162 run_command(&wsl, guid_copy)?;
163
164 println!("Shutting down WSL...");
165 match wsl.shutdown(false) {
166 Ok(_) => println!("Successfully shut down WSL"),
167 Err(e) => {
168 eprintln!("Failed to shut down WSL: {:?}", e);
169 return Err(e.into());
170 }
171 }
172
173 println!("Example completed successfully");
174 Ok(())
175}Sourcepub const fn bits(&self) -> u32
pub const fn bits(&self) -> u32
Get the underlying bits value.
The returned value is exactly the bits set in this flags value.
Sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
Convert from a bits value.
This method will return None if any unknown bits are set.
Sourcepub const fn from_bits_truncate(bits: u32) -> Self
pub const fn from_bits_truncate(bits: u32) -> Self
Convert from a bits value, unsetting any unknown bits.
Sourcepub const fn from_bits_retain(bits: u32) -> Self
pub const fn from_bits_retain(bits: u32) -> Self
Convert from a bits value exactly.
Sourcepub fn from_name(name: &str) -> Option<Self>
pub fn from_name(name: &str) -> Option<Self>
Get a flags value with the bits of a flag with the given name set.
This method will return None if name is empty or doesn’t
correspond to any named flag.
Sourcepub const fn intersects(&self, other: Self) -> bool
pub const fn intersects(&self, other: Self) -> bool
Whether any set bits in a source flags value are also set in a target flags value.
Sourcepub const fn contains(&self, other: Self) -> bool
pub const fn contains(&self, other: Self) -> bool
Whether all set bits in a source flags value are also set in a target flags value.
Sourcepub fn remove(&mut self, other: Self)
pub fn remove(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
remove won’t truncate other, but the ! operator will.
Sourcepub fn toggle(&mut self, other: Self)
pub fn toggle(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub fn set(&mut self, other: Self, value: bool)
pub fn set(&mut self, other: Self, value: bool)
Call insert when value is true or remove when value is false.
Sourcepub const fn intersection(self, other: Self) -> Self
pub const fn intersection(self, other: Self) -> Self
The bitwise and (&) of the bits in two flags values.
Sourcepub const fn union(self, other: Self) -> Self
pub const fn union(self, other: Self) -> Self
The bitwise or (|) of the bits in two flags values.
Sourcepub const fn difference(self, other: Self) -> Self
pub const fn difference(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Sourcepub const fn symmetric_difference(self, other: Self) -> Self
pub const fn symmetric_difference(self, other: Self) -> Self
The bitwise exclusive-or (^) of the bits in two flags values.
Sourcepub const fn complement(self) -> Self
pub const fn complement(self) -> Self
The bitwise negation (!) of the bits in a flags value, truncating the result.
Source§impl ImportFlags
impl ImportFlags
Sourcepub const fn iter(&self) -> Iter<ImportFlags>
pub const fn iter(&self) -> Iter<ImportFlags>
Yield a set of contained flags values.
Each yielded flags value will correspond to a defined named flag. Any unknown bits will be yielded together as a final flags value.
Sourcepub const fn iter_names(&self) -> IterNames<ImportFlags>
pub const fn iter_names(&self) -> IterNames<ImportFlags>
Yield a set of contained named flags values.
This method is like iter, except only yields bits in contained named flags.
Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
Trait Implementations§
Source§impl Binary for ImportFlags
impl Binary for ImportFlags
Source§impl BitAnd for ImportFlags
impl BitAnd for ImportFlags
Source§impl BitAndAssign for ImportFlags
impl BitAndAssign for ImportFlags
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
The bitwise and (&) of the bits in two flags values.
Source§impl BitOr for ImportFlags
impl BitOr for ImportFlags
Source§fn bitor(self, other: ImportFlags) -> Self
fn bitor(self, other: ImportFlags) -> Self
The bitwise or (|) of the bits in two flags values.
Source§type Output = ImportFlags
type Output = ImportFlags
| operator.Source§impl BitOrAssign for ImportFlags
impl BitOrAssign for ImportFlags
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
The bitwise or (|) of the bits in two flags values.
Source§impl BitXor for ImportFlags
impl BitXor for ImportFlags
Source§impl BitXorAssign for ImportFlags
impl BitXorAssign for ImportFlags
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
The bitwise exclusive-or (^) of the bits in two flags values.
Source§impl Clone for ImportFlags
impl Clone for ImportFlags
Source§fn clone(&self) -> ImportFlags
fn clone(&self) -> ImportFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImportFlags
impl Debug for ImportFlags
Source§impl Extend<ImportFlags> for ImportFlags
impl Extend<ImportFlags> for ImportFlags
Source§fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
fn extend<T: IntoIterator<Item = Self>>(&mut self, iterator: T)
The bitwise or (|) of the bits in each flags value.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl Flags for ImportFlags
impl Flags for ImportFlags
Source§const FLAGS: &'static [Flag<ImportFlags>]
const FLAGS: &'static [Flag<ImportFlags>]
Source§fn from_bits_retain(bits: u32) -> ImportFlags
fn from_bits_retain(bits: u32) -> ImportFlags
Source§fn contains_unknown_bits(&self) -> bool
fn contains_unknown_bits(&self) -> bool
true if any unknown bits are set.Source§fn from_bits_truncate(bits: Self::Bits) -> Self
fn from_bits_truncate(bits: Self::Bits) -> Self
Source§fn from_name(name: &str) -> Option<Self>
fn from_name(name: &str) -> Option<Self>
Source§fn iter_names(&self) -> IterNames<Self>
fn iter_names(&self) -> IterNames<Self>
Source§fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
fn intersects(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn contains(&self, other: Self) -> boolwhere
Self: Sized,
fn contains(&self, other: Self) -> boolwhere
Self: Sized,
Source§fn insert(&mut self, other: Self)where
Self: Sized,
fn insert(&mut self, other: Self)where
Self: Sized,
|) of the bits in two flags values.Source§fn remove(&mut self, other: Self)where
Self: Sized,
fn remove(&mut self, other: Self)where
Self: Sized,
&!). Read moreSource§fn toggle(&mut self, other: Self)where
Self: Sized,
fn toggle(&mut self, other: Self)where
Self: Sized,
^) of the bits in two flags values.Source§fn intersection(self, other: Self) -> Self
fn intersection(self, other: Self) -> Self
&) of the bits in two flags values.Source§fn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
&!). Read moreSource§fn symmetric_difference(self, other: Self) -> Self
fn symmetric_difference(self, other: Self) -> Self
^) of the bits in two flags values.Source§fn complement(self) -> Self
fn complement(self) -> Self
!) of the bits in a flags value, truncating the result.Source§impl FromIterator<ImportFlags> for ImportFlags
impl FromIterator<ImportFlags> for ImportFlags
Source§fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
fn from_iter<T: IntoIterator<Item = Self>>(iterator: T) -> Self
The bitwise or (|) of the bits in each flags value.
Source§impl Hash for ImportFlags
impl Hash for ImportFlags
Source§impl IntoIterator for ImportFlags
impl IntoIterator for ImportFlags
Source§impl LowerHex for ImportFlags
impl LowerHex for ImportFlags
Source§impl Not for ImportFlags
impl Not for ImportFlags
Source§impl Octal for ImportFlags
impl Octal for ImportFlags
Source§impl Ord for ImportFlags
impl Ord for ImportFlags
Source§fn cmp(&self, other: &ImportFlags) -> Ordering
fn cmp(&self, other: &ImportFlags) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ImportFlags
impl PartialEq for ImportFlags
Source§impl PartialOrd for ImportFlags
impl PartialOrd for ImportFlags
Source§impl PublicFlags for ImportFlags
impl PublicFlags for ImportFlags
Source§impl Sub for ImportFlags
impl Sub for ImportFlags
Source§fn sub(self, other: Self) -> Self
fn sub(self, other: Self) -> Self
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.
Source§type Output = ImportFlags
type Output = ImportFlags
- operator.Source§impl SubAssign for ImportFlags
impl SubAssign for ImportFlags
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
The intersection of a source flags value with the complement of a target flags value (&!).
This method is not equivalent to self & !other when other has unknown bits set.
difference won’t truncate other, but the ! operator will.