Skip to content

Commit

Permalink
better internal
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoczim committed Dec 31, 2023
1 parent 30294b2 commit 827e06b
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 45 deletions.
12 changes: 12 additions & 0 deletions src/location/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ impl AsRef<Self> for Component {
}
}

impl AsRef<str> for Component {
fn as_ref(&self) -> &str {
self.raw_contents()
}
}

impl fmt::Display for Component {
fn fmt(&self, fmtr: &mut fmt::Formatter) -> fmt::Result {
write!(fmtr, "{}", self.raw_contents())
}
}

#[cfg(test)]
mod test {
use super::Component;
Expand Down
22 changes: 13 additions & 9 deletions src/location/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{error::Error, fmt};
use super::{
external::{AsExternal, InvalidExternal},
id::{Id, InvalidId},

Check warning on line 5 in src/location/general.rs

View workflow job for this annotation

GitHub Actions / Check

unused imports: `InvalidId`, `InvalidPath`

Check warning on line 5 in src/location/general.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `InvalidId`, `InvalidPath`
internal::{Internal, InvalidInternal},
internal::{InvalidInternal, View},
path::{InvalidPath, Path},
};

Expand Down Expand Up @@ -37,20 +37,21 @@ impl fmt::Display for InvalidLocation {
impl Error for InvalidLocation {}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Location<I, P, E>
pub enum Location<P, I, E>
where
I: AsRef<Id>,
P: AsRef<Path>,
I: AsRef<Id>,
E: AsExternal,
{
Internal(Internal<I, P>),
Internal(View<P, I>),
External(E),
}

impl<I, P, E> Location<I, P, E>
/*
impl<P, I, E> Location<P, I, E>
where
I: AsRef<Id>,
P: AsRef<Path>,
I: AsRef<Id>,
E: AsExternal,
{
pub fn parse<'input>(input: &'input str) -> Result<Self, InvalidLocation>
Expand All @@ -62,15 +63,17 @@ where
if input.contains("://") {
Ok(Self::External(E::try_from(input)?))
} else {
Ok(Self::Internal(Internal::try_from(input)?))
Ok(Self::Internal(View::try_from(input)?))
}
}
}
*/

impl<'input, I, P, E> TryFrom<&'input str> for Location<I, P, E>
/*
impl<'input, P, I, E> TryFrom<&'input str> for Location<P, I, E>
where
I: AsRef<Id> + TryFrom<&'input str, Error = InvalidId>,
P: AsRef<Path> + TryFrom<&'input str, Error = InvalidPath>,
I: AsRef<Id> + TryFrom<&'input str, Error = InvalidId>,
E: AsExternal + TryFrom<&'input str, Error = InvalidExternal>,
{
type Error = InvalidLocation;
Expand All @@ -79,3 +82,4 @@ where
Self::parse(input)
}
}
*/
12 changes: 12 additions & 0 deletions src/location/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ impl AsRef<Self> for Id {
}
}

impl AsRef<str> for Id {
fn as_ref(&self) -> &str {
self.raw_contents()
}
}

impl fmt::Display for Id {
fn fmt(&self, fmtr: &mut fmt::Formatter) -> fmt::Result {
write!(fmtr, "{}", self.raw_contents())
}
}

#[cfg(test)]
mod test {
use super::Id;
Expand Down
Loading

0 comments on commit 827e06b

Please sign in to comment.