pub enum Markets {
Allowed(BTreeSet<Market>),
Excluded(BTreeSet<Market>),
}Variants§
Allowed(BTreeSet<Market>)
Any markets a package may be installed in.
Excluded(BTreeSet<Market>)
Any markets a package may not be installed in.
Implementations§
Source§impl Markets
impl Markets
pub const MAX_ITEMS: usize = 256usize
Sourcepub const fn new_allowed() -> Self
pub const fn new_allowed() -> Self
Makes a new, empty, allowed Markets.
Does not allocate anything on its own.
§Examples
use winget_types::installer::Markets;
let mut markets = Markets::new_allowed();Sourcepub fn allowed_from_iter<I, T>(markets: I) -> Result<Self, MarketsError>
pub fn allowed_from_iter<I, T>(markets: I) -> Result<Self, MarketsError>
Creates a new allowed Markets from an iterator of any type that implements AsRef<str.
§Errors
Returns an Err if any of the iterator items are not exactly 2 ASCII uppercase characters
or if the number of unique markets exceeds 256.
§Examples
use winget_types::installer::{Market, Markets};
let markets = Markets::allowed_from_iter(["US", "UK"]).unwrap();
let v: Vec<_> = markets.into_iter().collect();
assert_eq!(v, [Market::new("UK").unwrap(), Market::new("US").unwrap()]);Sourcepub unsafe fn allowed_from_iter_unchecked<I, T>(markets: I) -> Self
pub unsafe fn allowed_from_iter_unchecked<I, T>(markets: I) -> Self
Creates a new allowed Markets from an iterator of any type that implements AsRef<str
without checking whether each item is exactly 2 ASCII uppercase characters or if the number
of unique markets exceeds 256. This results in undefined behaviour if any item is not
exactly 2 ASCII uppercase characters or the number of unique markets exceeds 256.
§Safety
Each item must be exactly 2 ASCII uppercase characters and the number of unique markets must not exceed 256.
Sourcepub const fn new_excluded() -> Self
pub const fn new_excluded() -> Self
Makes a new, empty excluded Markets.
Does not allocate anything on its own.
§Examples
use winget_types::installer::Markets;
let mut markets = Markets::new_excluded();Sourcepub fn excluded_from_iter<I, T>(markets: I) -> Result<Self, MarketsError>
pub fn excluded_from_iter<I, T>(markets: I) -> Result<Self, MarketsError>
Creates a new excluded Markets from an iterator of any type that implements AsRef<str.
§Errors
Returns an Err if any of the iterator items are not exactly 2 ASCII uppercase characters
or if the number of unique markets exceeds 256.
§Examples
use winget_types::installer::{Market, Markets};
let markets = Markets::excluded_from_iter(["US", "UK"]).unwrap();
let v: Vec<_> = markets.into_iter().collect();
assert_eq!(v, [Market::new("UK").unwrap(), Market::new("US").unwrap()]);Sourcepub unsafe fn excluded_from_iter_unchecked<I, T>(markets: I) -> Self
pub unsafe fn excluded_from_iter_unchecked<I, T>(markets: I) -> Self
Creates a new excluded Markets from an iterator of any type that implements AsRef<str
without checking whether each item is exactly 2 ASCII uppercase characters or if the number
of unique markets exceeds 256. This results in undefined behaviour if any item is not
exactly 2 ASCII uppercase characters or the number of unique markets exceeds 256.
§Safety
Each item must be exactly 2 ASCII uppercase characters and the number of unique markets must not exceed 256.
Sourcepub fn add<T: AsRef<str>>(&mut self, market: T) -> Result<bool, MarketsError>
pub fn add<T: AsRef<str>>(&mut self, market: T) -> Result<bool, MarketsError>
Adds a market to the set.
Returns whether the market was newly inserted. That is:
- If the markets did not previously contain an equal market,
trueis returned. - If the markets already contained an equal market,
falseis returned, and the markets are not updated.
§Errors
Returns an error if adding the market would result in more than 256 markets.
Sourcepub fn contains<Q>(&self, market: &Q) -> bool
pub fn contains<Q>(&self, market: &Q) -> bool
Returns true if the set contains a market equal to the value.
The value may be any borrowed form of Market, but the ordering on the borrowed form must
match the ordering on the element type.
§Examples
use winget_types::installer::Markets;
let markets = Markets::allowed_from_iter(["US", "UK"]).unwrap();
assert_eq!(markets.contains("US"), true);
assert_eq!(markets.contains("DE"), false);Sourcepub fn remove<Q>(&mut self, market: &Q) -> bool
pub fn remove<Q>(&mut self, market: &Q) -> bool
If the set contains a market equal to the value, removes it from the set and drops it. Returns whether such a market was present.
The value may be any borrowed form of the set’s element type, but the ordering on the borrowed form must match the ordering on the element type.
§Examples
use winget_types::installer::Markets;
let mut markets = Markets::new_allowed();
markets.add("US").unwrap();
assert_eq!(markets.remove("US"), true);
assert_eq!(markets.remove("US"), false);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the set, removing all markets.
§Examples
use winget_types::installer::Markets;
let mut markets = Markets::new_allowed();
markets.add("US").unwrap();
markets.clear();
assert!(markets.is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of markets in the set.
§Examples
use winget_types::installer::Markets;
let mut markets = Markets::new_allowed();
assert_eq!(markets.len(), 0);
markets.add("US").unwrap();
assert_eq!(markets.len(), 1);Trait Implementations§
Source§impl<'market> IntoIterator for &'market Markets
impl<'market> IntoIterator for &'market Markets
Source§impl IntoIterator for Markets
impl IntoIterator for Markets
Source§impl Ord for Markets
impl Ord for Markets
Source§impl PartialOrd for Markets
impl PartialOrd for Markets
impl Eq for Markets
impl StructuralPartialEq for Markets
Auto Trait Implementations§
impl Freeze for Markets
impl RefUnwindSafe for Markets
impl Send for Markets
impl Sync for Markets
impl Unpin for Markets
impl UnwindSafe for Markets
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<I, C> CompactStringExt for C
impl<I, C> CompactStringExt for C
Source§fn concat_compact(self) -> CompactString
fn concat_compact(self) -> CompactString
CompactString Read moreSource§fn join_compact<S>(self, separator: S) -> CompactString
fn join_compact<S>(self, separator: S) -> CompactString
CompactString Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more