Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules: Create net module #820

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ramon-bernardo
Copy link
Contributor

@ramon-bernardo ramon-bernardo commented Sep 2, 2024

Add a net module, initially with SocketAddr and IpAddr types and their respective methods. TCP and UDP will be implemented in the future.

Copy link
Collaborator

@udoprog udoprog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers. So we're missing rune doctests, and the module has to be installed to be available. See where the module function is used for other modules.

@udoprog udoprog added the enhancement New feature or request label Sep 3, 2024
@ramon-bernardo
Copy link
Contributor Author

ramon-bernardo commented Sep 16, 2024

@udoprog how do I implement generating an IpAddr from a string, int, array of ints, etc., similar to the std IpAddr?

("127.0.0.1".parse())
(127, 0, 0, 1)
[127, 0, 0, 1]

@udoprog
Copy link
Collaborator

udoprog commented Sep 17, 2024

how do I implement generating an IpAddr from a string, int, array of ints, etc., similar to the std IpAddr?

You add the relevant methods to perform the conversion. Like the parse associated method, possible through a trait.

@udoprog udoprog changed the title Create net module modules: Create net module Oct 8, 2024
Comment on lines +125 to +130
/// An IP address, either IPv4 or IPv6.
#[derive(Debug, Any)]
#[rune(item = ::std::net)]
pub struct IpAddr {
inner: net::IpAddr,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a way to create an IpAddr. What is a preference: enum or constructors?

The std is IpAddr::V4(...) or V6(...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target is "Whatever Rust does" unless there is a good reason to deviate. So an Enum seems like the answer right now.

Make sure to add doc tests which exercises the constructors and pattern matching over the various variants to make sure they are installed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants