Enum apple_sdk::SdkSorting
source · pub enum SdkSorting {
None,
VersionDescending,
VersionAscending,
}Expand description
Sorting strategy to apply to SDK searches.
Variants§
None
Do not apply any sorting.
This will return SDKs in the order they are discovered from the input paths.
VersionDescending
Order SDKs by their version in descending order.
Newer SDKs will come before older SDKs.
VersionAscending
Order SDKs by their version in ascending order.
Older SDKs will come before newer SDKs.
Implementations§
source§impl SdkSorting
impl SdkSorting
sourcepub fn compare_version(
&self,
a: Option<&SdkVersion>,
b: Option<&SdkVersion>
) -> Ordering
pub fn compare_version(
&self,
a: Option<&SdkVersion>,
b: Option<&SdkVersion>
) -> Ordering
Examples found in repository?
src/search.rs (line 584)
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
pub fn search<SDK: AppleSdk>(&self) -> Result<Vec<SDK>, Error> {
let mut sdks = vec![];
// Track searched locations to avoid redundant work.
let mut searched_platform_dirs = HashSet::new();
let mut searched_sdks_dirs = HashSet::new();
for location in &self.locations {
if let Some(cb) = &self.progress_callback {
cb(SdkSearchEvent::SearchingLocation(location.clone()));
}
// Expand each location to SDKs.
let resolved = location.resolve_location()?;
let candidate_sdks = match &resolved {
SdkSearchResolvedLocation::None => {
vec![]
}
SdkSearchResolvedLocation::PlatformDirectories(dirs) => dirs
.iter()
// Apply platform filter.
.filter(|dir| {
if let Some(wanted_platform) = &self.platform {
if &dir.platform == wanted_platform {
if let Some(cb) = &self.progress_callback {
cb(SdkSearchEvent::PlatformDirectoryInclude(dir.path.clone()));
}
true
} else {
if let Some(cb) = &self.progress_callback {
cb(SdkSearchEvent::PlatformDirectoryExclude(dir.path.clone()));
}
false
}
} else {
if let Some(cb) = &self.progress_callback {
cb(SdkSearchEvent::PlatformDirectoryInclude(dir.path.clone()));
}
true
}
})
// Apply duplicate search filter.
.filter(|dir| {
if searched_platform_dirs.contains(dir.path()) {
false
} else {
searched_platform_dirs.insert(dir.path().to_path_buf());
true
}
})
.map(|dir| dir.find_sdks::<SDK>())
.collect::<Result<Vec<_>, Error>>()?
.into_iter()
.flatten()
.collect::<Vec<_>>(),
SdkSearchResolvedLocation::SdksDirectory(path) => {
if searched_sdks_dirs.contains(path) {
vec![]
} else {
searched_sdks_dirs.insert(path.clone());
SDK::find_in_directory(path)?
}
}
SdkSearchResolvedLocation::SdkDirectory(path)
| SdkSearchResolvedLocation::SdkDirectoryUnfiltered(path) => {
vec![SDK::from_directory(path)?]
}
};
let mut added_count = 0;
for sdk in candidate_sdks {
let include = if resolved.apply_sdk_filter() {
self.filter_sdk(&sdk)?
} else {
if let Some(cb) = &self.progress_callback {
cb(SdkSearchEvent::SdkFilterSkip(sdk.sdk_path()));
}
true
};
if include {
sdks.push(sdk);
added_count += 1;
}
}
if location.is_terminal() && added_count > 0 {
break;
}
}
// Sorting should be stable with None variant. But we can avoid the
// overhead.
if self.sorting != SdkSorting::None {
sdks.sort_by(|a, b| self.sorting.compare_version(a.version(), b.version()))
}
Ok(sdks)
}Trait Implementations§
source§impl Clone for SdkSorting
impl Clone for SdkSorting
source§fn clone(&self) -> SdkSorting
fn clone(&self) -> SdkSorting
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for SdkSorting
impl Debug for SdkSorting
source§impl Display for SdkSorting
impl Display for SdkSorting
source§impl PartialEq<SdkSorting> for SdkSorting
impl PartialEq<SdkSorting> for SdkSorting
source§fn eq(&self, other: &SdkSorting) -> bool
fn eq(&self, other: &SdkSorting) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl Copy for SdkSorting
impl Eq for SdkSorting
impl StructuralEq for SdkSorting
impl StructuralPartialEq for SdkSorting
Auto Trait Implementations§
impl RefUnwindSafe for SdkSorting
impl Send for SdkSorting
impl Sync for SdkSorting
impl Unpin for SdkSorting
impl UnwindSafe for SdkSorting
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.