« first day (1371 days earlier)      last day (2100 days later) » 

12:01 AM
@trentcl also reload the gist
fixed it
@trentcl the reason I'm thinking of doing this is because it's the exact opposite for me of "but I guess I can't think of an API where I would want to use one"
in almost all data structures I can think of I want Option<Key>, not Key
 
@orlp That's the thing... I always want Option<Key>, never NullableKey
 
@trentcl but keys are already nullable
because you can remove them from the slotmap
it's a complexity you have to deal with regardless
 
I see what you mean
 
the only difference between a key and a nullablekey is that there is one distinct value in a nullablekey that can never be a valid key
if you couldn't remove keys from the slotmap ever
I'd agree with you
I do make one promise
and that the only source of key.is_null is if you make one yourself with Key::null()
the slotmap will never give you a null key
so it's an entirely optional feature
 
It's similar to Weak::new() in that respect
 
12:08 AM
@trentcl Keys are very much weak pointers yes
that's the slotmap
the slotmap owns things
and gives out weak pointers to what it contains
@trentcl I'm confused
why does Weak::new say that it allocates space for T?
 
@trentcl alright
guess I'm not that weird for questioning that :P
 
I'm not sure why it wasn't written this way to begin with
I guess it's more special cases
Anyway, back to slotmap.
I think all the accesses to sm in gist.github.com/orlp/29180422ee302a8a4fde280605f85c27 are guarded by an .is_null() anyway
 
@trentcl the one's in push are unavoidable
because we actually have different behavior dependon the null
 
@orlp Of course. But you're still checking twice
 
12:19 AM
I think I can rewrite it
yes this is much better
sec
and also a much better example of why nullable keys are pretty cool here
 
also fwiw, crates.io/crates/optional may be of interest to you, although I don't think it applies directly
 
there, much better
oops fixing a little bug
(the len() checks should now be == 0)
done
@trentcl I think this is a much better example of how much nicer nullable keys are
 
@orlp I agree and I will allow myself to be convinced by this example
I still dislike it a little ;)
 
haha
I mean
it could lead to subtle bugs
because if you code like this null vs removed is not distinguished
 
Yeah, but I find it hard to argue against it on those grounds (because Weak is the same way, and for basically the same reason, as you said)
 
12:30 AM
I think I'll include it
strictly for speed reasons
if you don't want to use it
it's not forced upon you
you can always use Option<Key> explicitly
actually
I can't keep that promise if I implement Key::default, kinda?
 
@orlp eh, I think you've made a good case that nullable Keys are valid, so...
 
yeah, fuck it :P
only question is
Key::null vs Key::new
precedent says Key::new
but I kinda like Key::null explicitly
because people might definitely be confused into thinking that they can create and choose their keys
 
12:45 AM
@orlp null seems better to me as well.
 
 
13 hours later…
1:22 PM
Is there something I can add in my Cargo.toml to add default arguments for when I'm calling cargo build?
For example, to avoid typing

$ cargo +nightly build --target wasm32-unknown-unknown --release
I could make a bash script or something, but wondering if there is an official cargo way?
 
1:33 PM
@FrancisGagné I think that adding blanket impls is straight up not backwards compat. That's why TryFrom isn't stable, becasue they want to add a blanket impl involving !
@PeterHall half and half and no
rustup override set nightly
.cargo/config:
[build]
target = "wasm32-unknown-unknown"
I don't know anything for --release
TBH, I created a Makefile for my embedded work that's basically the same thing
 
1:50 PM
ah, ok, target is what I was missing
 
 
2 hours later…
3:51 PM
Look at @PeterHall in the "hot meta posts" sidebar
 
@Shepmaster drama again ?
 
nah, just flagging messages doesn't have good context meta.stackoverflow.com/questions/371128/…
 
4:08 PM
@Shepmaster Yeah just boring stuff
 
4:49 PM
@Shep It's good time to work on this runtime endianness crate.
 
is that so?
 
@Shepmaster What say you?
 
@E_net4 I forget my original concrete use case
;-)
 
But you know it exists. And prior research suggests that there is still no crate for this.
I'm thinking about creating a repo.
 
o_O i remembered such a package exists. iirc i used it once before
 
4:53 PM
@kennytm Linky?
 
something like a dynamic version of byteorder right?
 
Aye. And endianness doesn't count.
 
ouch XD what about scroll
 
5:07 PM
Hmm... looks like a canon.
 
@E_net4 why not?
 
@Shepmaster The methods do not take arbitrary Read endpoints, only &[u8].
And no writing at all.
scroll would have been interesting if it wasn't riddled with other odd stuph. It also does not do efficient reading/writing with a static endianness, like byteorder does. One has to pass an Endian enum value every time.
 
so you will use it like EndianReader(endian, my_reader).read_u32()?
 
 
1 hour later…
6:33 PM
@kennytm That's about the reason why we don't have it yet: no concrete API for this was proposed
That is an interesting idea, but it could be something else.
 
ah
though i don't see any other way you could do something else if you don't want to pass Endian every time
 
@kennytm that's not a big deal though?
.read_u32_le() .read_u32_be() and .read_u32(endian)
where the former two are shortcuts for the latter
 
@orlp that .read_u32(endian) is passing the Endian everytime...
i suppose E_net4's library doesn't need to support a static endian.
 
@kennytm if you don't want that you can use the _le or _be variants?
 
@kennytm It would integrate well with byteorder, so indeed.
 
6:39 PM
the point is the endian is unknown at compile-time
 
@kennytm eh I'm sorry?
 
As long as we can into_inner to retrieve the original RW, such a wrapper where we give the endianness once seems ok.
 
usually when you're read ing some integer from an encoded source
 
@orlp Not always, no.
 
I assume the protocol specifies one or the other byte order
 
that's so silly
 
@orlp Some protocols define byte ordering depending on the data itself.
 
@E_net4 that's fine
 
Silly or not, it's the state of things.
 
but still nothing to do with native byte order
.read_u32_le() .read_u32_be() and .read_u32(endian) still perfectly cover that
 
6:42 PM
nobody talked about native byte order :confused:
 
@kennytm I thought you did when you referred to it being unknown at compile-time
 
@orlp You don't have the third method in byteorder. At least not one supporting an arbitrary Read/Write.
 
@orlp the native byte order is known at compile time (thus byteorder has the NativeEndian type alias)
 
@orlp The data's endianness is unknown at compile time, not the system's endianness. :P
 
@orlp unknown means e.g. you need to read UTF-16 and the BOM defines whether those u16 are little or big endian.
 
6:44 PM
@E_net4 may I introduce you to early ARM systems? :P
it's LE or BE depending on whether a pin is connected
 
@orlp No need. Let's all do middle endian instead. A perfect balance.
4
 
@orlp well technically the late ARM has the SETEND instruction :p
 
assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap());
assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());
ew
I'm sorry but that's just bad design
 
Well...
What exactly do you have in mind? :)
 
.read_u16_be
why is it a type parameter?
there's just no good reason for it from what I can see
and actively hurts usage
 
6:49 PM
.read_u16()?.to_be() :shrug:
 
with all due respect, it kinda feels like a hamfisted "look ma - generics!" without regards for usability
 
@orlp It means one can write a read_foo<E> instead of a read_foo_le and a read_foo_be. Admittedly, the usefulness is a bit arguable.
One can alias the byte order type into something shorter: type LE = LittleEndian;
 
still awful
there's just no reason for it to be a type
it's not a type
also why are there so many read functions?
couldn't you just write read_le, read_be with generic return type T and infer T?
this is an even worse offender:
fn read_u16_into<T: ByteOrder>(&mut self, dst: &mut [u16]) -> Result<()> { ... }
fn read_u32_into<T: ByteOrder>(&mut self, dst: &mut [u32]) -> Result<()> { ... }
fn read_u64_into<T: ByteOrder>(&mut self, dst: &mut [u64]) -> Result<()> { ... }
fn read_i16_into<T: ByteOrder>(&mut self, dst: &mut [i16]) -> Result<()> { ... }
fn read_i32_into<T: ByteOrder>(&mut self, dst: &mut [i32]) -> Result<()> { ... }
fn read_i64_into<T: ByteOrder>(&mut self, dst: &mut [i64]) -> Result<()> { ... }
fn read_f32_into<T: ByteOrder>(&mut self, dst: &mut [f32]) -> Result<()> { ... }
isn't that a huge code smell?
fn read_into<T: ByteOrder, R>(&mut self, dst: &mut [R]) -> Result<()> { ... }
I don't want to seem overly negative, but I genuinely feel this is poor design
 
7:05 PM
Types are used as facts and markers all the time in rust. It's not costly, as it might be in other C-like languages, because rust has true ZSTs
To address your other point, it doesn't seem easy to write the implementation for arbitrary T - I guess it could be done for integral types reasonably well, but how are you going to handle it for arbytrary structures?
Heh. typo'd a pun
 
it's not about speed
it's about design
a marker type can be fine when it makes sense
but here it just doesn't
and it actively hurts ergonomics
no one wants to type .read_u16::<BigEndian>() or even .read_u16::<BE>()
@Zarenor forgive me if I'm wrong, but can't you make a new trait?
ByteSerializable or smt
and you implement it for each T that you want, such as i64, f64, etc
fn read_into_le<T: ByteOrder, R: ByteSerializable>(&mut self, dst: &mut [R]) -> Result<()> { ... }
fn read_into_be<T: ByteOrder, R: ByteSerializable>(&mut self, dst: &mut [R]) -> Result<()> { ... }
I wouldn't worry about arbitrary structures though, isn't that more serde territory?
I guess you could maybe make some macros that make sense for C-style structs
 
Mmmm. Sure, you could do that. I see where you're going.
 
eh you'd obviously remove T: ByteOrder :)
either way
it's bedtime for me
good night
 
 
4 hours later…
11:23 PM
What's going on here? This works: https://play.rust-lang.org/?gist=3160c9a6bbff6f858fa391af3a66a388&version=stable&mode=debug&edition=2015
but it doesn't work if i change the `Fn` to `FnOnce`.
I get:
> error[E0161]: cannot move a value of type std::ops::FnOnce() -> T + 'static: the size of std::ops::FnOnce() -> T + 'static cannot be statically determined
I don't follow why the size can be determined when it's Fn but not when it's FnOnce
Yikes. This conversation has been going on for a while: github.com/rust-lang/rust/issues/28796
 

« first day (1371 days earlier)      last day (2100 days later) »