10 Commits

Author SHA1 Message Date
3462b3cdb6
all: don't automatically convert userdata types to pointer types
One of the things I have done a better job of internalizing while
working with zig over the last few months is that the less magic that
exists, the better. In the case of parameterized functions, this means
that it is much better to restrict the range of types that are
permitted to be passed than to perform type manipulation. In other
words, it's more confusing to see a function that is parameterized
with `SomeType` taking a pointer to that type than having it be
parameterized directly to take the pointer. Obviously there are
exceptions to this rule, like std.mem.eql taking slices of its
parameterized type.

In fact, this new approach fixes some edge cases. Null userdata may now
be passed in, since the user can now actually specify an optional
pointer type (e.g. `?*void` may be used to provide always-null
userdata). Additionally, a pointer to a constant value can now be
passed in, which wasn't possible before (this could have been worked
around by use of constCast and being careful, but that's an
exceedingly bad option compared to having the type system work for
you).
2024-01-01 15:20:06 -08:00
6dc50530f1
message: a bit of cleanup around header iterators 2023-09-03 16:13:58 -07:00
b453ec3d92
all: add missing copyright headers
Tests are CC0/public domain because there's no reason for them not to
be. Examples are also CC0/public domain, but this may be a little bit
weird because they are largely straightforward ports of examples from
nats.c which carry the Apache license. However, I personally wrote
them against the zig bindings and I doubt anyone will end up in a
court of law due to their software containing uselessly trivial
example code.
2023-09-02 15:04:46 -07:00
226d678e68
examples: make request_reply slightly more interesting 2023-08-24 20:23:19 -07:00
2e06f44aa8
examples: add pub_bytes
This was the point that I realized there's no reason to have the string
variants of the publishing methods. But also there's not really much
point in porting the other getting-started examples, since we've
covered all their functionality in the existing examples
(actually, this one is redundant too, but I have already done it, so
it's getting grandfathered in).

Porting some of the more interesting examples might be a good idea, but
those have a weird argument parser that I don't really want to port
(even though it is very simple in the way that it works). For the most
part, I think writing unit tests will do a better of flexing the
bindings.
2023-08-23 22:35:27 -07:00
65ab46f714
connection: eliminate String method variants
After contemplating this for a little bit, there's no point in exposing
these separately from the plain variants. Even nats.c internally calls
its plain variants after calling `strlen` on the input. Zig benefits
from having nicer pointer types than C, so we get "string" handling
for free from the fact that the standard variants take slices anyway.
2023-08-23 22:27:33 -07:00
18205a5533
examples: add statistics to request_reply
I should probably write some tests instead.
2023-08-23 22:18:45 -07:00
b101e0acd2
message: more iterators, less problems
This seems like a pretty nice way to do this, since it lets us produce
the sliced version of each value rather than the somewhat janky many
pointer.
2023-08-23 22:03:25 -07:00
ebd3e64111
examples: port header example to zig
This looks a lot nicer than its c counterpart, in my opinion.
2023-08-23 01:05:37 -07:00
48962f27d9
add examples and integrate into build
I suppose the next step will be to translate the C examples into their
zig counterparts. This is also good dog food.
2023-08-21 23:51:58 -07:00