Doing some Rust stumbling. :thread:
# development
b
Doing some Rust stumbling. 🧵
1
I'm translating the following mapping (names are arbitrary):
Copy code
@dataclass(frozen=True)
class Bikeshed:
    input_digest: Digest
    immutable_input_digests: FrozenDict[str, Digest]
    use_nailgun: tuple[str, ...]
    output_files: tuple[str, ...]
    output_directories: tuple[str, ...]


@dataclass(frozen=True)
class CoalescedProcessBatch:
    files_to_bikesheds = FrozenDict[str, Bikeshed]
to the rust equivalent:
Copy code
#[derive(DeepSizeOf, Derivative, Clone, Debug, Eq, Serialize)]
#[derivative(PartialEq, Hash)]
pub struct Bikeshed {
  pub input_digests: InputDigests,
  pub output_files: BTreeSet<RelativePath>,
  pub output_directories: BTreeSet<RelativePath>,
}

#[derive(DeepSizeOf, Derivative, Clone, Debug, Eq, Serialize)]
#[derivative(PartialEq, Hash)]
pub struct CoalescedProcessBatch {
  pub files_to_bikesheds: BTreeMap<RelativePath, Bikeshed>,
The stumbling block here is that to turn
Copy code
input_digest: Digest
    immutable_input_digests: FrozenDict[str, Digest]
    use_nailgun: tuple[str, ...]
into a Rust
InputDigests
involves async store code, which
Python::with_gil
doesn't allow
The process lifting accomplishes this by having
Python::with_gil
return a future which we then
await
. I'm attempting the same, but stumbling very Hard. Namely because I'm doing this on N, instead of one (so trying to have a vector of futures and
try_join_all
them)
w
a gist of the code that isn’t working and the error would help
but you should be able to follow the same pattern of “return a
Vec<somesuch Future>
, then
try_join_all
it outside of the gil”
b
Yeah I think I got past this issue. With the rust compiler errors its so hard to know
I feel like I'm sprinkling
Ok(...)
s everywhere. I get the feeling if you're hammering out `Ok`s, everything IS NOT
Ok
😂
w
heh.
b
If I have an iter of `Result`s what does
collect()?
do?
w
collect always makes a concrete/explicit type (either passed to the call, or based on the left hand side of the assignment)
but generally what you want to do there is:
collect an iter of
Result<T, E>
into a
Result<Vec<T>, E>
:
.collect::<Result<Vec<_>, _>>()
is usually sufficient
blargh, slack kept eating my angle brackets… fixed now i think.
b
I'll have to post my code, this is getting tangly
👍 1
Well I think we got past that issue with the
collect()
code you posted
Oh no... my code compiles
w
then it probably works 😃
(unless you’ve got a deadlock… still can’t catch those, heh)
b
Hopefully everything is
Ok
?
PR has the code. Please take an anti-nausea pill prior to viewing: https://github.com/pantsbuild/pants/pull/15648