Skip to content

Commit

Permalink
Remove rpsl module, moving contents to root of crate (#64)
Browse files Browse the repository at this point in the history
* Remove unneeded files

* Fix spacing

* Remove rpsl module, moving contents to root of crate
  • Loading branch information
SRv6d authored Dec 26, 2023
1 parent 549a2f0 commit 408cc72
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 526 deletions.
File renamed without changes.
36 changes: 16 additions & 20 deletions src/rpsl/borrowed/attribute.rs → src/borrowed/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::rpsl::common::coerce_empty_value;
use crate::common::coerce_empty_value;

/// A type containing a string slice pointing to the name of an attribute.
#[derive(Debug, PartialEq, Eq, Clone)]
Expand All @@ -13,8 +13,8 @@ impl<'a> NameView<'a> {
self.0
}

pub fn to_owned(&self) -> crate::rpsl::Name {
crate::rpsl::Name::new(self.0.to_owned())
pub fn to_owned(&self) -> crate::Name {
crate::Name::new(self.0.to_owned())
}
}

Expand Down Expand Up @@ -53,12 +53,12 @@ impl<'a> ValueView<'a> {
}
}

pub fn to_owned(&self) -> crate::rpsl::Value {
pub fn to_owned(&self) -> crate::Value {
match self {
Self::SingleLine(value) => {
crate::rpsl::Value::new_single(value.map_or(None, |v| Some(v.to_string())))
crate::Value::new_single(value.map_or(None, |v| Some(v.to_string())))
}
Self::MultiLine(values) => crate::rpsl::Value::new_multi(
Self::MultiLine(values) => crate::Value::new_multi(
values
.iter()
.map(|v| v.map_or(None, |v| Some(v.to_string())))
Expand Down Expand Up @@ -164,13 +164,13 @@ impl<'a> AttributeView<'a> {

#[must_use]
/// Turn the view into an owned [`Attribute`](crate::Attribute).
pub fn to_owned(&self) -> crate::rpsl::Attribute {
crate::rpsl::Attribute::new(self.name.to_owned(), self.value.to_owned())
pub fn to_owned(&self) -> crate::Attribute {
crate::Attribute::new(self.name.to_owned(), self.value.to_owned())
}
}

impl PartialEq<crate::rpsl::Attribute> for AttributeView<'_> {
fn eq(&self, other: &crate::rpsl::Attribute) -> bool {
impl PartialEq<crate::Attribute> for AttributeView<'_> {
fn eq(&self, other: &crate::Attribute) -> bool {
other.name == self.name.as_str() && {
// TODO: Avoid unnecessary allocations.
let s: Vec<Option<&str>> = self.value.clone().into_iter().collect();
Expand Down Expand Up @@ -253,14 +253,13 @@ mod test {
fn eq_owned_attribute_is_eq() {
assert_eq!(
AttributeView::new_single("as-name", "REMARKABLE"),
crate::rpsl::Attribute::new("as-name".parse().unwrap(), "REMARKABLE".parse().unwrap())
crate::Attribute::new("as-name".parse().unwrap(), "REMARKABLE".parse().unwrap())
);
assert_eq!(
AttributeView::new_multi("remarks", vec!["Equal", "Values"]),
crate::rpsl::Attribute::new(
crate::Attribute::new(
"remarks".parse().unwrap(),
std::convert::TryInto::<crate::rpsl::Value>::try_into(vec!["Equal", "Values"])
.unwrap()
std::convert::TryInto::<crate::Value>::try_into(vec!["Equal", "Values"]).unwrap()
)
);
}
Expand All @@ -269,16 +268,13 @@ mod test {
fn ne_owned_attribute_ne() {
assert_ne!(
AttributeView::new_single("as-name", "REMARKABLE"),
crate::rpsl::Attribute::new(
"as-name".parse().unwrap(),
"UNREMARKABLE".parse().unwrap()
)
crate::Attribute::new("as-name".parse().unwrap(), "UNREMARKABLE".parse().unwrap())
);
assert_ne!(
AttributeView::new_multi("remarks", vec!["Some", "Values"]),
crate::rpsl::Attribute::new(
crate::Attribute::new(
"remarks".parse().unwrap(),
std::convert::TryInto::<crate::rpsl::Value>::try_into(vec!["Different", "Values"])
std::convert::TryInto::<crate::Value>::try_into(vec!["Different", "Values"])
.unwrap()
)
);
Expand Down
28 changes: 14 additions & 14 deletions src/rpsl/borrowed/object.rs → src/borrowed/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl<'a> ObjectView<'a> {
}

/// Turn the view into an owned [`Object`](crate::Object).
pub fn to_owned(&self) -> crate::rpsl::Object {
crate::rpsl::Object::new(
pub fn to_owned(&self) -> crate::Object {
crate::Object::new(
self.attributes
.iter()
.map(AttributeView::to_owned)
Expand Down Expand Up @@ -172,8 +172,8 @@ impl<'a> ObjectView<'a> {
}
}

impl PartialEq<crate::rpsl::Object> for ObjectView<'_> {
fn eq(&self, other: &crate::rpsl::Object) -> bool {
impl PartialEq<crate::Object> for ObjectView<'_> {
fn eq(&self, other: &crate::Object) -> bool {
// TODO: Avoid cloning
for (s, o) in self.clone().into_iter().zip(other.clone().into_iter()) {
if s != o {
Expand Down Expand Up @@ -236,17 +236,17 @@ mod test {
],
None,
);
let owned = crate::rpsl::Object::new(vec![
crate::rpsl::Attribute::new("role".parse().unwrap(), "ACME Company".parse().unwrap()),
crate::rpsl::Attribute::new(
let owned = crate::Object::new(vec![
crate::Attribute::new("role".parse().unwrap(), "ACME Company".parse().unwrap()),
crate::Attribute::new(
"address".parse().unwrap(),
"Packet Street 6".parse().unwrap(),
),
crate::rpsl::Attribute::new(
crate::Attribute::new(
"address".parse().unwrap(),
"128 Series of Tubes".parse().unwrap(),
),
crate::rpsl::Attribute::new("address".parse().unwrap(), "Internet".parse().unwrap()),
crate::Attribute::new("address".parse().unwrap(), "Internet".parse().unwrap()),
]);
assert_eq!(borrowed, owned);
}
Expand All @@ -262,17 +262,17 @@ mod test {
],
None,
);
let owned = crate::rpsl::Object::new(vec![
crate::rpsl::Attribute::new("role".parse().unwrap(), "ACME Company".parse().unwrap()),
crate::rpsl::Attribute::new(
let owned = crate::Object::new(vec![
crate::Attribute::new("role".parse().unwrap(), "ACME Company".parse().unwrap()),
crate::Attribute::new(
"address".parse().unwrap(),
"Packet Street 6".parse().unwrap(),
),
crate::rpsl::Attribute::new(
crate::Attribute::new(
"address".parse().unwrap(),
"128 Series of Tubes".parse().unwrap(),
),
crate::rpsl::Attribute::new("address".parse().unwrap(), "Internet".parse().unwrap()),
crate::Attribute::new("address".parse().unwrap(), "Internet".parse().unwrap()),
]);
assert_ne!(borrowed, owned);
}
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

pub use error::AttributeError;
pub use parser::{parse_object, parse_whois_response};
pub use rpsl::{Attribute, AttributeView, Object, ObjectView};

pub use self::borrowed::{AttributeView, ObjectView};
pub use self::owned::{Attribute, Object};
pub(crate) use self::owned::{Name, Value};

mod borrowed;
mod common;
#[allow(clippy::module_name_repetitions)]
mod error;
mod owned;
mod parser;
mod rpsl;
File renamed without changes.
8 changes: 4 additions & 4 deletions src/rpsl/owned/attribute.rs → src/owned/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
common::coerce_empty_value,
error::{InvalidNameError, InvalidValueError},
rpsl::common::coerce_empty_value,
};
use std::{fmt, str::FromStr};

Expand All @@ -10,7 +10,7 @@ pub struct Name(String);

impl Name {
/// Create a new `Name` from a String without validation.
pub(in crate::rpsl) fn new(name: String) -> Self {
pub(crate) fn new(name: String) -> Self {
Self(name)
}
}
Expand Down Expand Up @@ -71,12 +71,12 @@ impl Value {
}

/// Create a new `Value` from a String without validation.
pub(in crate::rpsl) fn new_single(value: Option<String>) -> Self {
pub(crate) fn new_single(value: Option<String>) -> Self {
Self::SingleLine(value)
}

/// Create a new `Value` from a vector of strings without validation.
pub(in crate::rpsl) fn new_multi(values: Vec<Option<String>>) -> Self {
pub(crate) fn new_multi(values: Vec<Option<String>>) -> Self {
Self::MultiLine(values)
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpsl/owned/object.rs → src/owned/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{fmt, ops::Index};
/// │ [address] ──┬─ Packet Street 6 │
/// │ ├─ 128 Series of Tubes │
/// │ └─ Internet │
/// │ [email] ─── rpsl-rs@github.com │
/// │ [email] ─── rpsl-rs@github.com
/// │ [nic-hdl] ─── RPSL1-RIPE │
/// │ [source] ─── RIPE │
/// └───────────────────────────────────────────────┘
Expand Down
2 changes: 1 addition & 1 deletion src/parser/component.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::rpsl::AttributeView;
use crate::AttributeView;
use nom::{
bytes::complete::{tag, take_while},
character::complete::{newline, space0},
Expand Down
2 changes: 1 addition & 1 deletion src/parser/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::component;
use crate::rpsl::ObjectView;
use crate::ObjectView;
use nom::{
branch::alt,
bytes::complete::tag,
Expand Down
6 changes: 0 additions & 6 deletions src/rpsl.rs

This file was deleted.

Loading

0 comments on commit 408cc72

Please sign in to comment.