IndividualAddress

Struct IndividualAddress 

Source
pub struct IndividualAddress { /* private fields */ }
Expand description

KNX Individual Address (Area.Line.Device)

Used to identify physical devices on the KNX bus.

§Examples

use knx_pico::IndividualAddress;

// Create from components
let addr = IndividualAddress::new(1, 1, 5).unwrap();
assert_eq!(addr.to_string(), "1.1.5");

// Create from raw u16
let addr = IndividualAddress::from(0x1105u16);
assert_eq!(addr.area(), 1);
assert_eq!(addr.line(), 1);
assert_eq!(addr.device(), 5);

// Parse from string
let addr: IndividualAddress = "1.1.5".parse().unwrap();
assert_eq!(u16::from(addr), 0x1105);

Implementations§

Source§

impl IndividualAddress

Source

pub const MAX_AREA: u8 = 15u8

Maximum area value (4 bits)

Source

pub const MAX_LINE: u8 = 15u8

Maximum line value (4 bits)

Source

pub const MAX_DEVICE: u8 = 255u8

Maximum device value (8 bits)

Source

pub fn new(area: u8, line: u8, device: u8) -> Result<Self>

Create a new Individual Address from components.

§Arguments
  • area - Area (0-15)
  • line - Line (0-15)
  • device - Device (0-255)
§Errors

Returns KnxError::AddressOutOfRange if any component is out of range.

§Examples
use knx_pico::IndividualAddress;

let addr = IndividualAddress::new(1, 1, 5)?;
assert_eq!(addr.to_string(), "1.1.5");
Source

pub fn from_array(parts: [u8; 3]) -> Result<Self>

Create from a 3-element array [area, line, device].

Convenient for creating addresses from array literals.

§Examples
use knx_pico::IndividualAddress;

let addr = IndividualAddress::from_array([1, 1, 5])?;
assert_eq!(addr.to_string(), "1.1.5");
Source

pub const fn raw(self) -> u16

Get the raw u16 representation of the address.

Source

pub const fn area(self) -> u8

Get the area component (0-15).

Source

pub const fn line(self) -> u8

Get the line component (0-15).

Source

pub const fn device(self) -> u8

Get the device component (0-255).

Source

pub fn encode(&self, buf: &mut [u8]) -> Result<usize>

Encode the address into a byte buffer (big-endian).

§Arguments
  • buf - Buffer to write to (must be at least 2 bytes)
§Errors

Returns KnxError::BufferTooSmall if buffer is too small.

Source

pub fn decode(buf: &[u8]) -> Result<Self>

Decode an address from a byte buffer (big-endian).

§Arguments
  • buf - Buffer to read from (must be at least 2 bytes)
§Errors

Returns KnxError::BufferTooSmall if buffer is too small.

Trait Implementations§

Source§

impl Clone for IndividualAddress

Source§

fn clone(&self) -> IndividualAddress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IndividualAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for IndividualAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Format for IndividualAddress

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl From<IndividualAddress> for u16

Source§

fn from(addr: IndividualAddress) -> u16

Converts to this type from the input type.
Source§

impl From<u16> for IndividualAddress

Source§

fn from(raw: u16) -> Self

Converts to this type from the input type.
Source§

impl FromStr for IndividualAddress

Source§

type Err = KnxError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for IndividualAddress

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for IndividualAddress

Source§

fn eq(&self, other: &IndividualAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for IndividualAddress

Source§

impl Eq for IndividualAddress

Source§

impl StructuralPartialEq for IndividualAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.