ityonemo

ityonemo

I’ve been internally using a library for IP and Mac addresses, and thought I’d open source the toolset. Some of the more interesting features include

  • guard clauses is_ip, is_ipv4, is_ipv6
  • support for CIDR block notation and ease of generating ipv4 broadcast addresses
  • sigil_i for IP addresses, ranges, and support for matching pinned variables (useful for /24 addresses)

Showing Posts 1 to 10

dimitarvp

dimitarvp

Pretty useful, thanks for that.

hauleth

hauleth

I would only change from_string/1 to parse/1 and parse!/1 instead to match the Integer and Float API more closely.

ityonemo

ityonemo OP

Parse returns a tuple that contains an extra binary useful for unit matching, no?

hauleth

hauleth

Yes, but in general I would assume IP.from_string/1 (or IP.parse/1) to return error tuple instead of throwing on error. You can pick any naming, but I would expect to have “failure-safe” way to parse data.

ityonemo

ityonemo OP

I think in elixir, .to_x and .from_x are designed to output naked values (String.to_integer/1 raises on a non-integer string), and be in pipelines, but your point about wanting something that outputs an error tuple on conversion is taken under advisement! function that returns an error tuple instead of raising on conversion · Issue #1 · ityonemo/net_address · GitHub

dimitarvp

dimitarvp

While you are generally correct I believe that having a bang variant like parse! signals even more clearly that the function might raise an exception which also implies that parse would return an ok/error tuple.

As another anecdotal evidence data point, I would also naively believe that from_string would not raise and would return an ok/error tuple as well (although this expectation might be severely misguided – I really don’t know).

ityonemo

ityonemo OP

The standard library’s Map.from_struct/1 does not return an error tuple. But doing a more comprehensive look, I see that the datetime/time/naivedatetime modules have from_* functions which do emit error tuples. I guess network addresses seem more like datetimes than structs, so I’ll go ahead and make the from_ functions emit tuples and have the bang equivalents throw.

ityonemo

ityonemo OP

updated in 0.2.0 to have bang functions and tuple functions for from_* functions, and as a bonus I implemented random and IP.SockAddr module.

mbklein

mbklein

I like how you used the m modifier on sigil_i. Nice touch.

ityonemo

ityonemo OP

updated in 0.3.0 to have ranges and subnets work in each other’s Kernel.in/2 implementations; also implements is_in function to detect membership in ranges and subnets, in guards.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews