use arrow_flight::FlightDescriptor;
use bytes::Bytes;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DataPath(Vec<String>);
impl DataPath {
pub fn new(segments: Vec<String>) -> Self {
Self(segments)
}
pub fn segments(&self) -> &[String] {
&self.0
}
pub fn display(&self) -> String {
self.0.join("/")
}
}
impl From<Vec<String>> for DataPath {
fn from(segments: Vec<String>) -> Self {
Self::new(segments)
}
}
impl From<Vec<&str>> for DataPath {
fn from(segments: Vec<&str>) -> Self {
Self::new(segments.into_iter().map(String::from).collect())
}
}
pub trait FlightDescriptorExt {
fn path_segments(&self) -> Option<Vec<String>>;
fn command_bytes(&self) -> Option<&Bytes>;
fn to_data_path(&self) -> Option<DataPath>;
}
impl FlightDescriptorExt for FlightDescriptor {
fn path_segments(&self) -> Option<Vec<String>> {
if self.path.is_empty() {
None
} else {
Some(self.path.clone())
}
}
fn command_bytes(&self) -> Option<&Bytes> {
if self.cmd.is_empty() {
None
} else {
Some(&self.cmd)
}
}
fn to_data_path(&self) -> Option<DataPath> {
self.path_segments().map(DataPath::new)
}
}