mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-30 11:50:38 +00:00
fix: correct impl Clear for &[u8] (#7081)
* fix: correct impl Clear for &[u8] * fix: clippy Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> --------- Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
This commit is contained in:
@@ -32,6 +32,8 @@ use std::{fmt, slice, vec};
|
||||
|
||||
use bytes::Bytes;
|
||||
|
||||
const NULL_BYTES: &[u8] = &[];
|
||||
|
||||
/// anything that can be cleared
|
||||
pub trait Clear {
|
||||
/// Clear this make, make it equivalent to newly created object.
|
||||
@@ -39,7 +41,9 @@ pub trait Clear {
|
||||
}
|
||||
|
||||
impl Clear for &[u8] {
|
||||
fn clear(&mut self) {}
|
||||
fn clear(&mut self) {
|
||||
*self = NULL_BYTES;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clear for Option<T> {
|
||||
@@ -512,3 +516,18 @@ impl<T: fmt::Debug> fmt::Debug for RepeatedField<T> {
|
||||
self.as_ref().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::repeated_field::RepeatedField;
|
||||
|
||||
#[test]
|
||||
fn test_null_ptr() {
|
||||
let mut vec: RepeatedField<&'static [u8]> = RepeatedField::new();
|
||||
let borrowed_value = vec.push_default();
|
||||
*borrowed_value = b"hello";
|
||||
vec.clear();
|
||||
let new_value = vec.push_default();
|
||||
assert!((*new_value).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user