#With the `bitvec` crate, how can I repeatedly `.split_at_mut` a `BitSlice`?

37 messages · Page 1 of 1 (latest)

fathom musk
#

The method signature of split_at_mut is:

pub fn split_at_mut(
    &mut self,
    mid: usize
) -> (&mut BitSlice<T::Alias, O>, &mut BitSlice<T::Alias, O>)

Note that it takes a BitSlice<T> and produces two BitSlice<<T as BitStore>::Alias>s. The problem is that when you split_at_mut one of the BitSlice<<T as BitStore>::Alias>s, you get two BitSlice<<<T as BitStore>::Alias as BitStore>::Alias>s. So, if I want to repeatedly split a BitSlice, the type gets longer and longer.

How can I keep the type from repeatedly getting longer?

brave girder
fathom musk
#

I'll look into how that's implemented. Thanks for the pointer.

brave girder
fathom musk
#

Yes, the iterator type that returns.

brave girder
#

I just searched for _mut with ctrl+f at that documentation and looked for something like that

brave girder
#

I dont think there is a method for splitting based on an iterator or Vec of indicies, which might be faster if things dont get optimized, but I think split_mut is what you want

#

or .split_inclusive_mut

brave girder
lilac nimbus
#

<u8 as BitStore>::Alias is BitSafeU8, but <BitSafeU8 as BitStore>::Alias is also BitSafeU8

#

This appears to be true for all integer types, at a glance

#

Also, the Alias of Cell<Int> or AtomicInt is Self, so they don't even nest once.

#

Or, in other words, unless you're generic over the BitStore, this impl doesn't actually require you to nest aliases forever.

#

At worst you have to convert to BitSafeInt (probably by splitting once) and then you can just keep splitting that

fathom musk
lilac nimbus
#

Then... good luck.

fathom musk
#

I have to see whether there are any aliases whos aliases aren't themselves. If there aren't any, I'll see if the memory representation changes and see about just transmuting it if not.

lilac nimbus
#

u8 isn't its own alias.

#

That's BitSafeU8

fathom musk
#

I mean the initial aliases having themselves as aliases.

lilac nimbus
#

Though there might be a .remove_alias method

#

(unsafe, of course)

fathom musk
#

Like <T as BitStore>::Alias = <<T as BitStore>::Alias as BitStore>::Alias for all T.

pallid iris
fathom musk
pallid iris
#

idk, looks like it could work but it's kinda recursive

#

so rustc might scream at you

#

or maybe ```rs
where
T: BitStore<Alias = A>,
A: BitStore<Alias = A>,

#

I'm 99% sure this one should work

#

and it's simpler

fathom musk
#

It seems to work.

#

?eval ```rust
trait Trait {
type A;
}

impl Trait for String {
type A = &'static str;
}

impl Trait for &'static str {
type A = &'static str;
}

fn f<T, U>(_: T)
where
T: Trait<A = U>,
U: Trait<A = U>,
{}

spare pathBOT
#
     Running `target/debug/playground`

()