Skip to content

Make DefaultUnderlyingGraph and SwhLabeling newtypes

vlorentz requested to merge newtype-underlyinggraph into master

This simplifies some error messages by not including the whole type.

For example, this code:

use std::path::PathBuf;
use swh_graph::graph::*;

pub fn main() {
    let graph = load_unidirectional(PathBuf::from("./graph")).unwrap()
        //.load_all_properties().unwrap()
        .load_labels().unwrap();

    swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
}

errors with:

error[E0277]: the trait bound `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<DefaultUnderlyingGraph, swh_graph::labeling::SwhLabeling>>: Deref` is not satisfied
 --> rust/examples/bad.rs:9:5
  |
9 |     swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deref` is not implemented for `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<DefaultUnderlyingGraph, swh_graph::labeling::SwhLabeling>>`, which is required by `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<DefaultUnderlyingGraph, swh_graph::labeling::SwhLabeling>>: SwhGraphWithProperties`
  |
  = help: the trait `SwhGraphWithProperties` is implemented for `SwhUnidirectionalGraph<SwhGraphProperties<MAPS, TIMESTAMPS, PERSONS, CONTENTS, STRINGS, LABELNAMES>, G>`
  = note: required for `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<DefaultUnderlyingGraph, swh_graph::labeling::SwhLabeling>>` to implement `SwhGraphWithProperties`

instead of:

error[E0277]: the trait bound `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<BvGraph<DynCodesDecoderFactory<dsi_bitstream::traits::endianness::BigEndian, MmapHelper<u32>, sux::dict::elias_fano::EliasFano<sux::rank_sel::select_adapt_const::SelectAdaptConst<sux::bits::bit_vec::BitVec<&[usize]>, &[usize], 12, 4>, sux::bits::bit_field_vec::BitFieldVec<usize, &[usize]>>>>, BitStreamLabeling<dsi_bitstream::traits::endianness::BigEndian, swh_graph::labeling::MmapReaderSupplier<dsi_bitstream::traits::endianness::BigEndian>, swh_graph::labeling::SwhDeserializer, epserde::deser::mem_case::MemCase<sux::dict::elias_fano::EliasFano<sux::rank_sel::select_adapt_const::SelectAdaptConst<sux::bits::bit_vec::BitVec<&[usize]>, &[usize], 12, 4>, sux::bits::bit_field_vec::BitFieldVec<usize, &[usize]>>>>>>: Deref` is not satisfied
 --> rust/examples/bad.rs:9:5
  |
9 |     swh_graph::stdlib::find_latest_snp(&graph, 42).unwrap();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deref` is not implemented for `SwhUnidirectionalGraph<(), Zip<BvGraph<DynCodesDecoderFactory<BigEndian, MmapHelper<u32>, ...>>, ...>>`, which is required by `SwhUnidirectionalGraph<(), swh_graph::webgraph::labels::Zip<BvGraph<DynCodesDecoderFactory<dsi_bitstream::traits::endianness::BigEndian, MmapHelper<u32>, sux::dict::elias_fano::EliasFano<sux::rank_sel::select_adapt_const::SelectAdaptConst<sux::bits::bit_vec::BitVec<&[usize]>, &[usize], 12, 4>, sux::bits::bit_field_vec::BitFieldVec<usize, &[usize]>>>>, BitStreamLabeling<dsi_bitstream::traits::endianness::BigEndian, swh_graph::labeling::MmapReaderSupplier<dsi_bitstream::traits::endianness::BigEndian>, swh_graph::labeling::SwhDeserializer, epserde::deser::mem_case::MemCase<sux::dict::elias_fano::EliasFano<sux::rank_sel::select_adapt_const::SelectAdaptConst<sux::bits::bit_vec::BitVec<&[usize]>, &[usize], 12, 4>, sux::bits::bit_field_vec::BitFieldVec<usize, &[usize]>>>>>>: SwhGraphWithProperties`
  |
  = help: the trait `SwhGraphWithProperties` is implemented for `SwhUnidirectionalGraph<SwhGraphProperties<MAPS, TIMESTAMPS, PERSONS, CONTENTS, STRINGS, LABELNAMES>, G>`
  = note: required for `SwhUnidirectionalGraph<(), Zip<BvGraph<DynCodesDecoderFactory<BigEndian, MmapHelper<u32>, ...>>, ...>>` to implement `SwhGraphWithProperties`
  = note: the full name for the type has been written to '/home/dev/swh-environment/swh-graph/target/debug/examples/bad-43e2af49a1f119e1.long-type-6411538841830264330.txt'
  = note: consider using `--verbose` to print the full type name to the console
Edited by vlorentz

Merge request reports