Implement From trait for MappedPort to facilitate conversions between tuple and pb_shared::MappedPort

This commit is contained in:
Noor 2025-01-30 20:14:33 +05:30
parent a2899ba5a2
commit 6e1b185383
Signed by: noormohammedb
GPG Key ID: D83EFB8B3B967146

@ -256,6 +256,21 @@ impl From<Resource> for pb_shared::Resource {
} }
} }
impl From<(u16, u16)> for pb_shared::MappedPort {
fn from(val: (u16, u16)) -> Self {
Self {
host_port: val.0 as u32,
container_port: val.1 as u32,
}
}
}
impl From<pb_shared::MappedPort> for (u16, u16) {
fn from(val: pb_shared::MappedPort) -> Self {
(val.host_port as u16, val.container_port as u16)
}
}
impl Config { impl Config {
pub fn from_path(path: &str) -> Result<Self, Box<dyn std::error::Error>> { pub fn from_path(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
let config_str = std::fs::read_to_string(path)?; let config_str = std::fs::read_to_string(path)?;