Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/value/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Array {
Array::IpNetwork(v) => v.is_empty(),
#[cfg(feature = "with-mac_address")]
Array::MacAddress(v) => v.is_empty(),
Array::Null(_) => true,
Array::Null(_) => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm Null should be empty right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the is_null method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty array => '{}'
null array => NULL

}
}

Expand Down Expand Up @@ -530,7 +530,7 @@ impl std::fmt::Debug for ArrayIterValue<'_> {
}
}

impl<'a> Iterator for ArrayIterValue<'a> {
impl Iterator for ArrayIterValue<'_> {
type Item = Option<Value>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
16 changes: 11 additions & 5 deletions src/value/with_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ macro_rules! impl_value_vec {
fn try_from_value(v: Value) -> Result<Vec<Option<Self>>, ValueTypeErr> {
match v {
Value::Array(Array::$vari(inner)) => Ok(inner.into_vec()),
Value::Array(Array::Null(ArrayType::$vari)) => Ok(vec![]),
_ => Err(ValueTypeErr)
}
}
Expand Down Expand Up @@ -106,6 +107,7 @@ impl ValueType for Vec<Option<u8>> {
fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
match v {
Value::Array(Array::TinyUnsigned(inner)) => Ok(inner.into_vec()),
Value::Array(Array::Null(ArrayType::TinyUnsigned)) => Ok(vec![]),
_ => Err(ValueTypeErr),
}
}
Expand Down Expand Up @@ -195,7 +197,7 @@ macro_rules! impl_uuid_fmt_pg_array_element {
.into_iter()
.map(|opt| opt.map(Self::from))
.collect()),
Value::Array(Array::Null(_)) => Ok(vec![]),
Value::Array(Array::Null(ArrayType::Uuid)) => Ok(vec![]),
_ => Err(ValueTypeErr),
}
}
Expand Down Expand Up @@ -241,11 +243,15 @@ impl Value {
matches!(self, Self::Array(_))
}

pub fn as_ref_array(&self) -> Option<&Array> {
pub fn as_array(&self) -> Option<&Array> {
match self {
Self::Array(v) if !v.is_null() => Some(v),
Self::Array(_) => None,
_ => panic!("not Value::Array"),
Self::Array(v) => Some(v),
_ => None,
}
}

#[deprecated(since = "1.0.0", note = "Use Value::as_array instead.")]
pub fn as_ref_array(&self) -> Option<&Array> {
self.as_array()
}
}
Loading