Skip to content

Commit

Permalink
Replace to_gatt with as_gatt
Browse files Browse the repository at this point in the history
  • Loading branch information
petekubiak committed Feb 26, 2025
1 parent 5be62cc commit d275a02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions host/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ impl FixedGattValue for CharacteristicProps {
Ok(CharacteristicProps(data[0]))
}

fn to_gatt(&self) -> &[u8] {
FixedGattValue::to_gatt(&self.0)
fn as_gatt(&self) -> &[u8] {
FixedGattValue::as_gatt(&self.0)
}
}

Expand Down
12 changes: 6 additions & 6 deletions host/src/types/gatt_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait FixedGattValue: FromGatt {

/// Converts to gatt bytes.
/// Must return a slice of len Self::SIZE
fn to_gatt(&self) -> &[u8];
fn as_gatt(&self) -> &[u8];
}

/// Trait to allow conversion of a type to gatt bytes
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<T: FixedGattValue> AsGatt for T {
const MAX_SIZE: usize = Self::SIZE;

fn as_gatt(&self) -> &[u8] {
<Self as FixedGattValue>::to_gatt(self)
<Self as FixedGattValue>::as_gatt(self)
}
}

Expand Down Expand Up @@ -91,7 +91,7 @@ impl<T: Primitive> FixedGattValue for T {
}
}

fn to_gatt(&self) -> &[u8] {
fn as_gatt(&self) -> &[u8] {
// SAFETY
// - Slice is of type u8 so data is guaranteed valid for reads of any length
// - Data and len are tied to the address and size of the type
Expand All @@ -110,7 +110,7 @@ impl FixedGattValue for bool {
}
}

fn to_gatt(&self) -> &[u8] {
fn as_gatt(&self) -> &[u8] {
match self {
true => &[0x01],
false => &[0x00],
Expand Down Expand Up @@ -183,7 +183,7 @@ impl AsGatt for &'static [u8] {
const MIN_SIZE: usize = 0;
const MAX_SIZE: usize = usize::MAX;

fn to_gatt(&self) -> &[u8] {
fn as_gatt(&self) -> &[u8] {
self
}
}
Expand All @@ -192,7 +192,7 @@ impl AsGatt for crate::types::uuid::Uuid {
const MIN_SIZE: usize = 2;
const MAX_SIZE: usize = 16;

fn to_gatt(&self) -> &[u8] {
fn as_gatt(&self) -> &[u8] {
self.as_raw()
}
}
Expand Down

0 comments on commit d275a02

Please sign in to comment.