Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to automerge@0.5.0 #33

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
toolchain: 1.70.0
default: true
components: rustfmt
- uses: Swatinem/rust-cache@v2
Expand All @@ -29,7 +29,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
toolchain: 1.70.0
default: true
components: clippy
- uses: Swatinem/rust-cache@v2
Expand All @@ -56,7 +56,7 @@ jobs:
strategy:
matrix:
toolchain:
- 1.65.0
- 1.70.0
- nightly
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
steps:
Expand All @@ -77,7 +77,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
toolchain: 1.70.0
default: true
- uses: Swatinem/rust-cache@v2
- run: ./scripts/ci/build-test
Expand All @@ -90,7 +90,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
toolchain: 1.70.0
default: true
- uses: Swatinem/rust-cache@v2
- run: ./scripts/ci/build-test
Expand Down
4 changes: 2 additions & 2 deletions autosurgeon-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ thiserror = "1.0.37"

[dev-dependencies]
autosurgeon = { path = "../autosurgeon" }
automerge = { version = "0.4.0" }
automerge-test = "0.3.0"
automerge = { version = "0.5.0" }
automerge-test = "0.4.0"
3 changes: 1 addition & 2 deletions autosurgeon-derive/src/reconcile/enum_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ impl<'a> EnumKey<'a> {
let key_type_name = self.type_name();

let outer_id_ident = syn::Ident::new("outer_id", Span::mixed_site());
let inner_id_ident = syn::Ident::new("inner_id", Span::mixed_site());

let non_unit_match_arms = self
.variants
Expand Down Expand Up @@ -492,7 +491,7 @@ impl<'a> EnumKey<'a> {
_ => Ok(autosurgeon::reconcile::LoadKey::KeyNotFound)
},
Value::Object(ObjType::Map) => {
let Some((discriminant_str, inner_ty, #inner_id_ident)) = doc.map_range(&#outer_id_ident, ..).next() else {
let Some(automerge::iter::MapRangeItem{key: discriminant_str, ..}) = doc.map_range(&#outer_id_ident, ..).next() else {
return Ok(autosurgeon::reconcile::LoadKey::KeyNotFound);
};
match discriminant_str {
Expand Down
4 changes: 2 additions & 2 deletions autosurgeon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ repository = "https://github.com/automerge/autosurgeon"
readme = "../README.md"

[dependencies]
automerge = { version = "0.4.0" }
automerge = { version = "0.5.0" }
thiserror = "1.0.37"
smol_str = { version = "^0.1.21" }
autosurgeon-derive = { path = "../autosurgeon-derive", version = "0.6.0" }
similar = "2.2.1"
uuid = { version = "1.2.2", optional = true }

[dev-dependencies]
automerge-test = "0.3.0"
automerge-test = "0.4.0"

[features]
uuid = ["dep:uuid"]
46 changes: 25 additions & 21 deletions autosurgeon/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ pub trait ReadDoc {
) -> Result<Option<(Value<'_>, ObjId)>, AutomergeError>;

fn object_type<O: AsRef<ObjId>>(&self, obj: O) -> Option<am::ObjType>;
fn map_range<O: AsRef<ObjId>, R: RangeBounds<String>>(
&self,
fn map_range<'a, O: AsRef<ObjId>, R: RangeBounds<String>>(
&'a self,
obj: O,
range: R,
) -> am::MapRange<'_, R>;
) -> am::iter::MapRange<'a, R>
where
R: RangeBounds<String> + 'a;

fn list_range<O: AsRef<ObjId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
) -> am::ListRange<'_, R>;
) -> am::iter::ListRange<'_, R>;

fn length<O: AsRef<ObjId>>(&self, obj: O) -> usize;

Expand Down Expand Up @@ -80,7 +82,7 @@ pub trait Doc: ReadDoc {
&mut self,
obj: O,
pos: usize,
del: usize,
del: isize,
text: &str,
) -> Result<(), AutomergeError>;
}
Expand All @@ -105,19 +107,22 @@ impl ReadDoc for am::AutoCommit {
.unwrap_or(None)
}

fn map_range<O: AsRef<ObjId>, R: RangeBounds<String>>(
&self,
fn map_range<'a, O: AsRef<ObjId>, R: RangeBounds<String>>(
&'a self,
obj: O,
range: R,
) -> am::MapRange<'_, R> {
) -> am::iter::MapRange<'a, R>
where
R: RangeBounds<String> + 'a,
{
am::ReadDoc::map_range(self, obj, range)
}

fn list_range<O: AsRef<ObjId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
) -> am::ListRange<'_, R> {
) -> am::iter::ListRange<'_, R> {
am::ReadDoc::list_range(self, obj, range)
}

Expand All @@ -134,7 +139,7 @@ impl ReadDoc for am::AutoCommit {
}
}

impl<'a, Obs: am::transaction::Observation> ReadDoc for am::transaction::Transaction<'a, Obs> {
impl<'a> ReadDoc for am::transaction::Transaction<'a> {
type Parents<'b> = am::Parents<'b> where Self: 'b;
fn get_heads(&self) -> Vec<am::ChangeHash> {
am::transaction::Transactable::base_heads(self)
Expand All @@ -154,19 +159,18 @@ impl<'a, Obs: am::transaction::Observation> ReadDoc for am::transaction::Transac
.unwrap_or(None)
}

fn map_range<O: AsRef<ObjId>, R: RangeBounds<String>>(
&self,
obj: O,
range: R,
) -> am::MapRange<'_, R> {
fn map_range<'b, O: AsRef<ObjId>, R>(&'b self, obj: O, range: R) -> am::iter::MapRange<'b, R>
where
R: RangeBounds<String> + 'b,
{
am::ReadDoc::map_range(self, obj, range)
}

fn list_range<O: AsRef<ObjId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
) -> am::ListRange<'_, R> {
) -> am::iter::ListRange<'_, R> {
am::ReadDoc::list_range(self, obj, range)
}

Expand Down Expand Up @@ -203,19 +207,19 @@ impl ReadDoc for am::Automerge {
.unwrap_or(None)
}

fn map_range<O: AsRef<ObjId>, R: RangeBounds<String>>(
&self,
fn map_range<'a, O: AsRef<ObjId>, R: RangeBounds<String> + 'a>(
&'a self,
obj: O,
range: R,
) -> am::MapRange<'_, R> {
) -> am::iter::MapRange<'a, R> {
am::ReadDoc::map_range(self, obj, range)
}

fn list_range<O: AsRef<ObjId>, R: RangeBounds<usize>>(
&self,
obj: O,
range: R,
) -> am::ListRange<'_, R> {
) -> am::iter::ListRange<'_, R> {
am::ReadDoc::list_range(self, obj, range)
}

Expand Down Expand Up @@ -290,7 +294,7 @@ impl<T: am::transaction::Transactable + ReadDoc> Doc for T {
&mut self,
obj: O,
pos: usize,
del: usize,
del: isize,
text: &str,
) -> Result<(), AutomergeError> {
am::transaction::Transactable::splice_text(self, obj, pos, del, text)
Expand Down
4 changes: 2 additions & 2 deletions autosurgeon/src/hydrate/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
hash::Hash,
};

use automerge::ObjType;
use automerge::{self as am, ObjType};

use crate::{Hydrate, HydrateError};

Expand Down Expand Up @@ -50,7 +50,7 @@ where
match obj_type {
ObjType::Map | ObjType::Table => doc
.map_range(obj.clone(), ..)
.map(move |(key, _, _)| {
.map(move |am::iter::MapRangeItem { key, .. }| {
let val = V::hydrate(doc, obj, key.into())?;
let key_parsed: K = extract_key(key)?;
Ok((key_parsed, val))
Expand Down
14 changes: 8 additions & 6 deletions autosurgeon/src/reconcile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub trait TextReconciler {
fn splice<S: AsRef<str>>(
&mut self,
pos: usize,
delete: usize,
delete: isize,
insert: S,
) -> Result<(), Self::Error>;
fn heads(&self) -> &[automerge::ChangeHash];
Expand Down Expand Up @@ -748,14 +748,16 @@ impl<'a, D: Doc> MapReconciler for InMap<'a, D> {
}

struct InMapEntries<'a> {
map_range: automerge::MapRange<'a, RangeFull>,
map_range: automerge::iter::MapRange<'a, RangeFull>,
}

impl<'a> Iterator for InMapEntries<'a> {
type Item = (&'a str, automerge::Value<'a>);

fn next(&mut self) -> Option<Self::Item> {
self.map_range.next().map(|(key, val, _)| (key, val))
self.map_range
.next()
.map(|automerge::iter::MapRangeItem { key, value, .. }| (key, value))
}
}

Expand All @@ -766,14 +768,14 @@ struct InSeq<'a, D> {
}

struct ItemsInSeq<'a> {
list_range: automerge::ListRange<'a, RangeFull>,
list_range: automerge::iter::ListRange<'a, RangeFull>,
}

impl<'a> Iterator for ItemsInSeq<'a> {
type Item = automerge::Value<'a>;

fn next(&mut self) -> Option<Self::Item> {
self.list_range.next().map(|i| i.1)
self.list_range.next().map(|i| i.value)
}
}

Expand Down Expand Up @@ -848,7 +850,7 @@ impl<'a, D: Doc> TextReconciler for InText<'a, D> {
fn splice<S: AsRef<str>>(
&mut self,
pos: usize,
delete: usize,
delete: isize,
text: S,
) -> Result<(), Self::Error> {
self.doc
Expand Down
18 changes: 13 additions & 5 deletions autosurgeon/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ impl Text {
/// # Arguments
///
/// * pos - The index to start the splice at
/// * del - The number of characters to delete
/// * del - The number of characters to delete. This can be negative to indicate deleting `del`
/// characters preceding `pos`
/// * insert - The characters to insert
///
/// The `pos` index uses the same logic as [`String::replace_range`]. This means
Expand All @@ -97,11 +98,18 @@ impl Text {
/// value.splice(i, 0, "amazing ");
/// assert_eq!(value.as_str(), "some amazing value");
/// ```
pub fn splice<S: AsRef<str>>(&mut self, pos: usize, del: usize, insert: S) {
pub fn splice<S: AsRef<str>>(&mut self, pos: usize, del: isize, insert: S) {
let start = if del < 0 {
pos.saturating_sub(del.unsigned_abs())
} else {
pos
};
match &mut self.0 {
State::Fresh(v) => v.replace_range(pos..(pos + del), insert.as_ref()),
State::Fresh(v) => {
v.replace_range(start..(start + del.unsigned_abs()), insert.as_ref())
}
State::Rehydrated { value, edits, .. } => {
value.replace_range(pos..(pos + del), insert.as_ref());
value.replace_range(start..(start + del.unsigned_abs()), insert.as_ref());
edits.push(Splice {
pos,
delete: del,
Expand Down Expand Up @@ -138,7 +146,7 @@ enum State {
#[derive(Clone)]
struct Splice {
pos: usize,
delete: usize,
delete: isize,
insert: String,
}

Expand Down
Loading