rusticl/util: add Properties::is_empty() and len()
Reviewed-by: @LingMan Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32268>
This commit is contained in:
@@ -404,7 +404,7 @@ where
|
||||
|
||||
fn count(&self) -> usize {
|
||||
// Properties are value pairs terminated with a 0 value.
|
||||
self.props.len() * 2 + 1
|
||||
self.len() * 2 + 1
|
||||
}
|
||||
|
||||
fn write_to(&self, out: &mut [MaybeUninit<T>]) {
|
||||
@@ -414,7 +414,7 @@ where
|
||||
}
|
||||
|
||||
// need to terminate with a 0 value
|
||||
out[self.props.len() * 2].write(T::default());
|
||||
out[self.len() * 2].write(T::default());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ pub struct Properties<T> {
|
||||
pub props: Vec<(T, T)>,
|
||||
}
|
||||
|
||||
impl<T: Copy + PartialEq + Default> Properties<T> {
|
||||
impl<T: Copy + Default> Properties<T> {
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
pub fn from_ptr_raw(mut p: *const T) -> Vec<T> {
|
||||
pub fn from_ptr_raw(mut p: *const T) -> Vec<T>
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
let mut res: Vec<T> = Vec::new();
|
||||
|
||||
if !p.is_null() {
|
||||
@@ -22,7 +25,10 @@ impl<T: Copy + PartialEq + Default> Properties<T> {
|
||||
}
|
||||
|
||||
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||
pub fn from_ptr(mut p: *const T) -> Option<Self> {
|
||||
pub fn from_ptr(mut p: *const T) -> Option<Self>
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
let mut res = Self::default();
|
||||
|
||||
if !p.is_null() {
|
||||
@@ -45,6 +51,16 @@ impl<T: Copy + PartialEq + Default> Properties<T> {
|
||||
|
||||
Some(res)
|
||||
}
|
||||
|
||||
/// Returns true when there is no property available.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.props.is_empty()
|
||||
}
|
||||
|
||||
/// Returns the amount of key/value pairs available.
|
||||
pub fn len(&self) -> usize {
|
||||
self.props.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for Properties<T> {
|
||||
|
||||
Reference in New Issue
Block a user