-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This removes all the manual type conversion between glib::Bytes and MacAddr6, which is a lot safer, as there's no need to validate the property value anymore.
- Loading branch information
Showing
9 changed files
with
83 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright Sebastian Wiesner <[email protected]> | ||
|
||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//! Simple MAC address type on top of [`glib::Bytes`]. | ||
//! | ||
//! While this is not the most efficient approach it allows storing the MAC | ||
//! address as a GLib property. | ||
use std::fmt::Display; | ||
use std::ops::Deref; | ||
use std::str::FromStr; | ||
|
||
use macaddr::MacAddr6; | ||
|
||
/// Boxed [`MacAddr6`]. | ||
/// | ||
/// Define a MAC address type for GLib, by boxing a [`MacAdd6`]. | ||
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, glib::Boxed)] | ||
#[boxed_type(name = "MacAdd6")] | ||
pub struct MacAddr6Boxed(MacAddr6); | ||
|
||
impl From<MacAddr6> for MacAddr6Boxed { | ||
fn from(value: MacAddr6) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl FromStr for MacAddr6Boxed { | ||
type Err = macaddr::ParseError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
MacAddr6::from_str(s).map(Into::into) | ||
} | ||
} | ||
|
||
impl Deref for MacAddr6Boxed { | ||
type Target = MacAddr6; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Display for MacAddr6Boxed { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} |