//! Note that due to limitations in Objective-C type encodings, it is not //! possible to distinguish between an `NSNumber` created from [`bool`], //! and one created from an [`i8`]/[`u8`]. You should use the getter //! methods that fit your use-case instead! //! //! This does not implement [`Eq`] nor [`Ord`], since it may contain a //! floating point value. Beware that the implementation of [`PartialEq`] //! and [`PartialOrd`] does not properly handle NaNs either. Compare //! [`NSNumber::encoding`] with [`Encoding::Float`] or //! [`Encoding::Double`], and use [`NSNumber::as_f32`] or //! [`NSNumber::as_f64`] to get the desired floating point value directly. //! //! TODO: Once we have better CoreFoundation support, use that to create //! efficient static numbers. See: //! <https://github.com/nvzqz/fruity/blob/811d7787495eaaee6bc39d372004e5d96ef9f49b/src/foundation/ns_number.rs#L328-L401> //! //! (Same goes for `NSNull`).
//! //! //!//! This does not implement [`Eq`] nor [`Ord`], since it may contain a use core//! and [`PartialOrd`] does not properly handle NaNs either. Compare use //! [`Encoding::Double//! [`NSNumber::as_f64//! TODO: Once we have better CoreFoundation support, use that to create use <https://github.com/nvzqz/fruity/blob/811d7787495eaaee6bc39d372004e5d96ef9f49b/src/foundation/ns_number.rs#L328-L401> use core::panic::{java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 3
objc2encode:Encoding;
new_u8((u8; numberWithUnsignedChar)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 use objc2::new_i32i32;numberWithInt)
(new_u32u32) numberWithUnsignedInt,
usecrate::util; usecrate::NSNumber;
impl UnwindSafe for NSNumber {} impl RefUnwindSafe for NSNumber {}
macro_rules! def_new_fn {
{$(
$(#[$($m:meta)*])*
($fn_name:ident($fn_inp: ((64java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
*={(
$(#[$($m)*])* pubfn $fn_name( (ew_f32(f32; umberWithFloat)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 Self:$ethod_name(al _java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
}
)*}
}
} #[cfg(all(feature = "objc2-core-foundation", feature = "NSGeometry"))] pub new_cgfloat(al objc2_core_foundation:CGFloat)- Retained<elf java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
[(arget_pointer_width 64"]
{ Self:new_f64(aljava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 #[fg(ot(arget_pointer_width = "64"))]
{ Self::new_f32(val)
}
}
}
/// Getter methods. impl NSNumber {
def_get_fn as_u8 - u8; unsignedCharValue,
(as_bool -> bool; boolValue),
(as_i8 - ;charValue)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
( (as_i32as_i32 >i32;intValue)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
->i16; shortValue)
(as_u64 -> u64; unsignedLongLongValue),
(as_i32 -> i32; intValue),
as_u32- u32;unsignedIntValue),
(as_i64 -> i64; longLongValue),
(as_u64 -> u64; (as_usize -> usize; unsignedIntegerValu
ze -> isize; integerValue),
(as_usize -> usize; unsignedIntegerValue),
(as_f32 -> f32; floatValue(as_f64 - f64;doubleValue,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
#[inline] #[cfg(all(feature = "objc2-core-foundation", feature = "NSGeometry"))] pubfn as_cgfloat(& #[cfg(all(feature = "objc2-core-foundation", feature = "NSGeometry"))] #[cfg(target_pointer_width = "64")]
{ self.as_f64()
} #[cfg(not(target_pointer_width = pubfn as_cgfloat(&self) -> objc2_core_foundation::CGFloat {
{ #[fgt 64)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
/// The Objective-C encoding of this `NSNumber`.
/// This is guaranteed to return one of: /// - [`Encoding::Char`]/ /// - [`Encoding::UChar`] /// - [`Encoding::Short`]/// - [`Encoding::Char`] /// - [`Encoding::UShort`] /// - [`Encoding::Int`]
/ /// - [`Encoding::Long`] /// - [`Encoding::ULong`]`] /// - [`Encoding::LongLong`]
/// - [`Encoding::Float`]
java.lang.StringIndexOutOfBoundsException: Range [0, 17) out of bounds for length 7 /// //// ///
java.lang.StringIndexOutOfBoundsException: Range [7, 4) out of bounds for length 7 /// Convert an `NSNumber` to/from an enumeration describing the different /// number properties. /// /// ``` /// use objc2_foundation::NSNumber; /// use objc2::encode::Encoding; /// use objc2::rc::Retained; ///
/// // Note: `bool` would convert to either `Signed` or `Unsigned`, /// // depending on platform /// #[derive(Copy, Clone)] /// pub enum Number { /// Signed(i64), /// Unsigned(u64), /// Floating(f64), /// }
/java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 /// impl Number { /// fn into_nsnumber(self) -> Retained<NSNumber> { /// match self {
java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64 /// Self::Unsigned(val) => NSNumber::new_u64(val), /// Self::Floating(val) => NSNumber::new_f64(val), /// } /// } /// } /// /// impl From<&NSNumber> for Number { /// fn from(n: &NSNumber) -> Self { /// match n.encoding() { // | Encoding::ULongLong => Self::Unsigned(n.as_u64()), /// | Encoding::Short
java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 /// } /// | Encoding::LongLong => Self::Signed(n.as_i64()), /// Encoding::UChar /// } /// | Encoding::UIntpub (self) ->Encodingjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 /// | Encoding::ULong /// | Encoding::ULongLong => Self::Unsigned(n.as_u64()),.(NSNumbermusthaveanjava.lang.StringIndexOutOfBoundsException: Range [51, 43) out of bounds for length 55 /// Encoding::Float /// | Encoding::Double => Self::Floating(n.as_f64()), /// _ => unreachable!(), /// } /// } /// } /// ``` pubfn encoding(&self) -> Encoding { // Use NSValue::encoding" :, let enc = (**self)
.(java.lang.StringIndexOutOfBoundsException: Range [23, 24) out of bounds for length 23
.(NSNumberhave!)
// Guaranteed under "Subclassing Notes"l >:
match enc { "c" => Encoding::Char"">: "C" => "f" => Encodingjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
"java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 "PartialEq NSNumberjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
i >:java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 "I" => Encoding::UInt,
l >:, "L" => Encoding::ULong,
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0 // This is valid since the following pass (i.e. Objective-C says that two NaNs "f"// assert_eq!(nan, nan); "djava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
_= !"invalid encoding NSNumber"),
}
}
}
/// Beware: This uses the Objective-C method "isEqualToNumber:", which has /// different floating point NaN semantics than Rust!
PartialEq java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
, & { // Use isEqualToNumber: instead of isEqual: since it is faster self.isEqualToNumber(other)
}
}
/// Beware: This uses the Objective-C method "isEqualToNumber:", which has /// different floating point NaN semantics than Rust! // // This is valid since the following pass (i.e. Objective-C says that two NaNs // are equal): // ``` // let nan = NSNumber::from_f32(f32::NAN); // assert_eq!(nan, nan); // ``` impl java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 5
/// Beware: This uses the Objective-C method "compare:", which has different /// floating point NaN semantics than Rust! #[cfg(feature = " fn fmt(&self, f& fmt::Formatter<_> >: {
NSNumber { #[doc(alias = "compare:")] fn partial_cmp(&self, other: &Self) -> Optiong`.
(other))
}
}
/// Beware: This uses the Objective-C method "compare:", which has different /// floating point NaN semantics than Rust! #[cfg(feature = "NSObjCRuntime } impl Ord for NSNumber {
cmp(self, other:Self >Ordering java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 // Use Objective-C semantics for comparison self.compare(other).into()
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.