fix git merge conflict
All checks were successful
Run Check Script / check (pull_request) Successful in 1m24s
All checks were successful
Run Check Script / check (pull_request) Successful in 1m24s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
|
||||
pub struct MacAddress(pub [u8; 6]);
|
||||
|
||||
impl MacAddress {
|
||||
@@ -19,6 +19,14 @@ impl From<&MacAddress> for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MacAddress {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("MacAddress")
|
||||
.field(&String::from(self))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for MacAddress {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&String::from(self))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{fmt, str::FromStr};
|
||||
use log::trace;
|
||||
use serde::Serialize;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
/// Simple error type for port parsing failures.
|
||||
#[derive(Debug)]
|
||||
@@ -74,7 +74,8 @@ pub enum PortDeclaration {
|
||||
Single(PortLocation),
|
||||
/// A Named port, often used for virtual ports such as PortChannels. Example
|
||||
/// ```rust
|
||||
/// PortDeclaration::Named("1".to_string())
|
||||
/// # use harmony_types::switch::PortDeclaration;
|
||||
/// PortDeclaration::Named("1".to_string());
|
||||
/// ```
|
||||
Named(String),
|
||||
/// A strictly sequential range defined by two endpoints using the hyphen separator (`-`).
|
||||
@@ -140,8 +141,19 @@ impl PortDeclaration {
|
||||
match PortLocation::from_str(port_str) {
|
||||
Ok(loc) => Ok(PortDeclaration::Single(loc)),
|
||||
Err(e) => {
|
||||
trace!("Failed to parse PortLocation {port_str} : {e}");
|
||||
trace!("Falling back on named port");
|
||||
let segments: Vec<&str> = port_str.split('/').collect();
|
||||
let segment_count = segments.len();
|
||||
|
||||
// Logic:
|
||||
// If it has 3 segments but failed (e.g., "1/A/1"), it's an InvalidSegment.
|
||||
// If it has MORE than 3 segments (e.g., "1/1/1/1" or "1/1/1/"), it's an InvalidFormat.
|
||||
if segment_count >= 3 {
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
// Otherwise, it's something else entirely (e.g., "eth0", "vlan10"),
|
||||
// so we treat it as a Named port.
|
||||
trace!("Falling back on named port for: {port_str}");
|
||||
Ok(PortDeclaration::Named(port_str.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user