api: Allow to have an endpoint both defined and deprecated in Matrix 1.0
This commit is contained in:
parent
d78c3e11f1
commit
2296f16ea0
@ -168,8 +168,8 @@ impl VersionHistory {
|
|||||||
/// - In stable_paths:
|
/// - In stable_paths:
|
||||||
/// - matrix versions are in ascending order
|
/// - matrix versions are in ascending order
|
||||||
/// - no matrix version is referenced twice
|
/// - no matrix version is referenced twice
|
||||||
/// - deprecated's version comes after the latest version mentioned in stable_paths, and only if
|
/// - deprecated's version comes after the latest version mentioned in stable_paths, except for
|
||||||
/// any stable path is defined
|
/// version 1.0, and only if any stable path is defined
|
||||||
/// - removed comes after deprecated, or after the latest referenced stable_paths, like
|
/// - removed comes after deprecated, or after the latest referenced stable_paths, like
|
||||||
/// deprecated
|
/// deprecated
|
||||||
pub const fn new(
|
pub const fn new(
|
||||||
@ -268,8 +268,10 @@ impl VersionHistory {
|
|||||||
if let Some(deprecated) = deprecated {
|
if let Some(deprecated) = deprecated {
|
||||||
if let Some(prev_seen_version) = prev_seen_version {
|
if let Some(prev_seen_version) = prev_seen_version {
|
||||||
let ord_result = prev_seen_version.const_ord(&deprecated);
|
let ord_result = prev_seen_version.const_ord(&deprecated);
|
||||||
if ord_result.is_eq() {
|
if !deprecated.is_legacy() && ord_result.is_eq() {
|
||||||
// prev_seen_version == deprecated
|
// prev_seen_version == deprecated, except for 1.0.
|
||||||
|
// It is possible that an endpoint was both made stable and deprecated in the
|
||||||
|
// legacy versions.
|
||||||
panic!("deprecated version is equal to latest stable path version")
|
panic!("deprecated version is equal to latest stable path version")
|
||||||
} else if ord_result.is_gt() {
|
} else if ord_result.is_gt() {
|
||||||
// prev_seen_version > deprecated
|
// prev_seen_version > deprecated
|
||||||
@ -648,6 +650,15 @@ impl MatrixVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Internal function to check if this version is the legacy (v1.0) version in const-fn contexts
|
||||||
|
const fn is_legacy(&self) -> bool {
|
||||||
|
let self_parts = self.into_parts();
|
||||||
|
|
||||||
|
use konst::primitive::cmp::cmp_u8;
|
||||||
|
|
||||||
|
cmp_u8(self_parts.0, 1).is_eq() && cmp_u8(self_parts.1, 0).is_eq()
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the default [`RoomVersionId`] for this `MatrixVersion`.
|
/// Get the default [`RoomVersionId`] for this `MatrixVersion`.
|
||||||
pub fn default_room_version(&self) -> RoomVersionId {
|
pub fn default_room_version(&self) -> RoomVersionId {
|
||||||
match self {
|
match self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user