Code Monkey home page Code Monkey logo

yrb's Introduction

Yrb


yrb

Ruby bindings for yrs ("wires")

Yrb is a Ruby binding for Y-CRDT. It provides distributed data types that enable real-time collaboration between devices. Yrb can sync data with any other platform that has a Y-CRDT binding, allowing for seamless cross-domain communication.

The library is a thin wrapper around Yrs, taking advantage of the safety and performance of Rust.

Installation

Add this line to your application's Gemfile:

gem 'y-rb'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install y-rb

Required RubyGems version

If you want to use y-rb on x86_64-linux-musl systems, you most likely need to update your system RubyGems due to a bug in RubyGems < 3.3.21. For older RubyGems versions, the platform is described as x86_64-linux-musl, but x86_64-linux is fetched instead.

gem update --system

Usage

# creates a new document and text structure
local = Y::Doc.new 
local_text = local.get_text("my text")

# add some data to the text structure
local_text << "hello"  
  
# create a remote document sharing the same text structure
remote = Y::Doc.new 
remote_text = remote.get_text("my text")  

# retrieve the current state of the remote document
remote_state = remote.state  

# create an update for the remote document based on the current
# state of the remote document
update = local.diff(remote_state)  
  
# apply update to remote document
remote.sync(update)  

puts remote_text.to_s == local_text.to_s # true  

More examples.

Development

Make sure you have cargo available (2021 edition). The gem needs the lib to be built every time when there is a change.

cargo build --release

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Docs

You can run yard locally and open the docs with:

yard server 
open "http://0.0.0.0:8808/"

Decision log

For this gem, we maintain a decision log. Please consult it in case there is some ambiguity in terms of why certain implementation details look as they are.

License

The gem is available as open source under the terms of the MIT License.

yrb's People

Contributors

dependabot[bot] avatar eliias avatar stanhu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yrb's Issues

cannot install y-rb(v0.5.4) with Rails 7.1

Gemfile: Almost default rails gemfile and use y-rb latest version.

source "https://rubygems.org"

ruby "3.2.1"

gem "rails", "~> 7.1.3", ">= 7.1.3.2"
gem "pg", "~> 1.1"
gem "puma", ">= 5.0"
gem "tzinfo-data", platforms: %i[ windows jruby ]
gem "bootsnap", require: false

gem 'y-rb', '~> 0.5.4'

group :development, :test do
  gem "debug", platforms: %i[ mri windows ]
end

then bundle install

โžœ  hoge git:(main) โœ— bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Installing y-rb 0.5.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/y-rb-0.5.4/ext/yrb
/Users/mackeee/.rbenv/versions/3.2.1/bin/ruby extconf.rb
checking for clang... yes
checking for clang++... yes
checking for ar... yes
checking for cargo... yes

current directory: /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/y-rb-0.5.4/ext/yrb
make DESTDIR\= sitearchdir\=./.gem.20240307-40854-qc09b2 sitelibdir\=./.gem.20240307-40854-qc09b2 clean

current directory: /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/y-rb-0.5.4/ext/yrb
make DESTDIR\= sitearchdir\=./.gem.20240307-40854-qc09b2 sitelibdir\=./.gem.20240307-40854-qc09b2
generating target/release/libyrb.dylib (release)
cargo rustc  --manifest-path ./Cargo.toml --target-dir target --lib --profile release -- -C linker=clang -L native=/Users/mackeee/.rbenv/versions/3.2.1/lib -L native=/opt/homebrew/opt/openssl@3/lib -L native=/opt/homebrew/opt/gmp/lib -C
link-arg=-Wl,-undefined,dynamic_lookup -l pthread
    Updating crates.io index
   Compiling libc v0.2.153
   Compiling proc-macro2 v1.0.78
   Compiling unicode-ident v1.0.12
   Compiling memchr v2.7.1
   Compiling glob v0.3.1
   Compiling cfg-if v1.0.0
   Compiling regex-syntax v0.8.2
   Compiling minimal-lexical v0.2.1
   Compiling either v1.10.0
   Compiling bindgen v0.69.4
   Compiling getrandom v0.1.16
   Compiling rustc-hash v1.1.0
   Compiling shlex v1.3.0
   Compiling bitflags v2.4.2
   Compiling lazycell v1.3.0
   Compiling libloading v0.8.3
   Compiling lazy_static v1.4.0
   Compiling shell-words v1.1.0
   Compiling thiserror v1.0.57
   Compiling serde v1.0.197
   Compiling itertools v0.12.1
   Compiling ppv-lite86 v0.2.17
   Compiling smallvec v1.13.1
   Compiling serde_json v1.0.114
   Compiling rb-sys-env v0.1.2
   Compiling itoa v1.0.10
   Compiling ryu v1.0.17
   Compiling atomic_refcell v0.1.13
   Compiling seq-macro v0.3.5
   Compiling aho-corasick v1.1.2
   Compiling nom v7.1.3
   Compiling clang-sys v1.7.0
   Compiling smallstr v0.3.0
   Compiling smallstr v0.2.0
   Compiling magnus v0.6.2
   Compiling quote v1.0.35
   Compiling rand_core v0.5.1
   Compiling syn v2.0.52
   Compiling rand_chacha v0.2.2
   Compiling rand v0.7.3
   Compiling regex-automata v0.4.6
   Compiling cexpr v0.6.0
   Compiling regex v1.10.3
   Compiling thiserror-impl v1.0.57
   Compiling magnus-macros v0.6.0
   Compiling lib0 v0.16.10
   Compiling yrs v0.17.4
   Compiling yrs v0.16.10
   Compiling rb-sys-build v0.9.90
   Compiling y-sync v0.3.1
   Compiling rb-sys v0.9.90
error[E0053]: method `decode` has an incompatible type for trait
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:300:47
    |
300 |     fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, lib0::error::Error> {
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                               |
    |                                               expected `yrs::encoding::read::Error`, found `lib0::error::Error`
    |                                               help: change the output type to match the trait: `Result<AwarenessUpdate, yrs::encoding::read::Error>`
    |
    = note: expected signature `fn(&mut D) -> Result<_, yrs::encoding::read::Error>`
               found signature `fn(&mut D) -> Result<_, lib0::error::Error>`

error[E0053]: method `decode` has an incompatible type for trait
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:186:47
    |
186 |     fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, lib0::error::Error> {
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                               |
    |                                               expected `yrs::encoding::read::Error`, found `lib0::error::Error`
    |                                               help: change the output type to match the trait: `Result<Message, yrs::encoding::read::Error>`
    |
    = note: expected signature `fn(&mut D) -> Result<_, yrs::encoding::read::Error>`
               found signature `fn(&mut D) -> Result<_, lib0::error::Error>`

error[E0053]: method `decode` has an incompatible type for trait
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:249:47
    |
249 |     fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, lib0::error::Error> {
    |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                               |
    |                                               expected `yrs::encoding::read::Error`, found `lib0::error::Error`
    |                                               help: change the output type to match the trait: `Result<SyncMessage, yrs::encoding::read::Error>`
    |
    = note: expected signature `fn(&mut D) -> Result<_, yrs::encoding::read::Error>`
               found signature `fn(&mut D) -> Result<_, lib0::error::Error>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:301:44
    |
301 |         let len: usize = decoder.read_var()?;
    |                                            ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<AwarenessUpdate, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:304:57
    |
304 |             let client_id: ClientID = decoder.read_var()?;
    |                                                         ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<AwarenessUpdate, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:305:48
    |
305 |             let clock: u32 = decoder.read_var()?;
    |                                                ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<AwarenessUpdate, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:306:45
    |
306 |             let json = decoder.read_string()?.to_string();
    |                                             ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<AwarenessUpdate, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:187:41
    |
187 |         let tag: u8 = decoder.read_var()?;
    |                                         ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:190:55
    |
190 |                 let msg = SyncMessage::decode(decoder)?;
    |                                                       ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:194:46
    |
194 |                 let data = decoder.read_buf()?;
    |                                              ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:195:62
    |
195 |                 let update = AwarenessUpdate::decode_v1(data)?;
    |                                                              ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:199:57
    |
199 |                 let reason = if decoder.read_var::<u8>()? == PERMISSION_DENIED {
    |                                                         ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:200:47
    |
200 |                     Some(decoder.read_string()?.to_string())
    |                                               ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:208:46
    |
208 |                 let data = decoder.read_buf()?;
    |                                              ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<Message, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:250:41
    |
250 |         let tag: u8 = decoder.read_var()?;
    |                                         ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<SyncMessage, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:253:45
    |
253 |                 let buf = decoder.read_buf()?;
    |                                             ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<SyncMessage, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:254:53
    |
254 |                 let sv = StateVector::decode_v1(buf)?;
    |                                                     ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<SyncMessage, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:258:45
    |
258 |                 let buf = decoder.read_buf()?;
    |                                             ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<SyncMessage, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0277]: `?` couldn't convert the error to `lib0::error::Error`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:262:45
    |
262 |                 let buf = decoder.read_buf()?;
    |                                             ^ the trait `From<yrs::encoding::read::Error>` is not implemented for `lib0::error::Error`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              <lib0::error::Error as From<lib0::json_parser::JsonParseError>>
              <lib0::error::Error as From<std::io::Error>>
    = note: required for `Result<SyncMessage, lib0::error::Error>` to implement `FromResidual<Result<Infallible, yrs::encoding::read::Error>>`

error[E0308]: mismatched types
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:324:17
    |
322 |         match Message::decode(self.0) {
    |               ----------------------- this expression has type `Result<Message, yrs::encoding::read::Error>`
323 |             Ok(msg) => Some(Ok(msg)),
324 |             Err(lib0::error::Error::EndOfBuffer(_)) => None,
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `yrs::encoding::read::Error`, found `lib0::error::Error`
    |
    = note: `lib0::error::Error` and `yrs::encoding::read::Error` have similar names, but are actually distinct types
note: `lib0::error::Error` is defined in crate `lib0`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lib0-0.16.10/src/error.rs:4:1
    |
4   | pub enum Error {
    | ^^^^^^^^^^^^^^
note: `yrs::encoding::read::Error` is defined in crate `yrs`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yrs-0.17.4/src/encoding/read.rs:6:1
    |
6   | pub enum Error {
    | ^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:325:36
    |
325 |             Err(error) => Some(Err(error)),
    |                                --- ^^^^^ expected `lib0::error::Error`, found `yrs::encoding::read::Error`
    |                                |
    |                                arguments to this enum variant are incorrect
    |
    = note: `yrs::encoding::read::Error` and `lib0::error::Error` have similar names, but are actually distinct types
note: `yrs::encoding::read::Error` is defined in crate `yrs`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yrs-0.17.4/src/encoding/read.rs:6:1
    |
6   | pub enum Error {
    | ^^^^^^^^^^^^^^
note: `lib0::error::Error` is defined in crate `lib0`
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lib0-0.16.10/src/error.rs:4:1
    |
4   | pub enum Error {
    | ^^^^^^^^^^^^^^
help: the type constructed contains `yrs::encoding::read::Error` due to the type of the argument passed
   --> /Users/mackeee/.cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/sync.rs:325:32
    |
325 |             Err(error) => Some(Err(error)),
    |                                ^^^^-----^
    |                                    |
    |                                    this argument influences the type of `Err`
note: tuple variant defined here
   --> /Users/mackeee/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:511:5
    |
511 |     Err(#[stable(feature = "rust1", since = "1.0.0")] E),
    |     ^^^

Some errors have detailed explanations: E0053, E0277, E0308.
For more information about an error, try `rustc --explain E0053`.
error: could not compile `y-sync` (lib) due to 21 previous errors
warning: build failed, waiting for other jobs to finish...
make: *** [target/release/libyrb.dylib] Error 101

make failed, exit code 2

Gem files will remain installed in /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/y-rb-0.5.4 for inspection.
Results logged to /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/extensions/arm64-darwin-23/3.2.0/y-rb-0.5.4/gem_make.out

  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:125:in `run'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `each'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `make'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:193:in `build_extension'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `each'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:852:in `build_extensions'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/rubygems_gem_installer.rb:76:in `build_extensions'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/source/rubygems.rb:205:in `install'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/installer/gem_installer.rb:54:in `install'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/installer/parallel_installer.rb:132:in `do_install'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/installer/parallel_installer.rb:123:in `block in worker_pool'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/worker.rb:62:in `apply_func'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/worker.rb:54:in `loop'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/worker.rb:54:in `process_queue'
  /Users/mackeee/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/worker.rb:90:in `block (2 levels) in create_threads'

An error occurred while installing y-rb (0.5.4), and Bundler cannot continue.

In Gemfile:
  y-rb

Hash stored in map causes panick, type inconsistency between JS and Ruby

We are attempting to modify the same ydoc in the browser using yjs, and on our server using yrb. I have a pretty simple setup client side (this is simplified further for the sake of this report, but captures our use case fairly):

const ydoc = new Y.Doc();
const localBinder = bindImmerYjs(ydoc.getMap("data"));

localBinder.update((s) => {
  return {
    testString: "foo",
    testInt: 1,
    testFloat: 3.1415,
    testBool: false,
    testArray: [1, "two", true],
    testHash: { a: 1, b: "2", c: false }
  }
})

This ydoc is encoded as a uint8array, base64'd, then sent to the server where it's saved to a file store. In ruby, we load this content and try to access these values. This is mostly working. Roughly, this looks like:

ydata = Base64.decode64(stored_data)
ydoc = Y::Doc.new
ydoc.transact { |tx| tx.apply(ydata.bytes.to_a) }

ymap = ydoc.get_map("data")

All that is working, but this is where we run into problems:

# Works as expected
ymap[:testString] # => "foo"
ymap[:testBool] # => false
ymap[:testFloat] # => 3.1415

# Works close enough, but still wrong
ymap[:testInt] # => 1.0 (notice this is a Float now)

# Panick!
ymap[:testArray]
ymap[:testHash]

These Panicks are identical, producing:

thread '<unnamed>' panicked at /bundle/ruby/3.1.0/gems/y-rb-0.5.2/ext/yrb/.rb-sys/stable/cargo/registry/src/index.crates.io-6f17d22bba15001f/yrs-0.16.9/src/doc.rs:775:41:
called `Option::unwrap()` on a `None` value

There's an obvious workaround here where we can encode our hashes and arrays as a JSON string, but if we're going to do that, we might as well encode the whole map as a JSON string instead of as a map in the first place.

Note that this is not a problem when we decode these values on the client side.

sync error

Hello! Thanks for the great work ๐Ÿ‘
Let me submit a bug report here.

Example code:

Let's say there's a Diff model to record every update from yjs doc.
The following code will raise an exception.

doc = Y::Doc.new
Page.first.diffs.order(:id).take(50).pluck(:diff).each do |diff|
  doc.sync(diff)
end

Exception:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/runner/work/yrb/yrb/tmp/cargo-vendor/yrs/src/block.rs:125:82
/app/vendor/bundle/ruby/3.1.0/gems/y-rb-0.3.0-aarch64-linux/lib/y/transaction.rb:22:in `ytransaction_apply_update': called `Option::unwrap()` on a `None` value (fatal)

Here's some other information that may help solve the bug:

  • If I take 40 diffs instead of 50, it works correctly.
  • If I give the same data to javascript yjs, then Y.applyUpdate can handle them properly without any errors.
    • It's my workaround to return every diff to the client for now.
// This works 
diffs.forEach((diff) => {
  Y.applyUpdate(this.ydoc, Uint8Array.from(diff))
})

Here are the 50 diffs I used above.

[[1, 3, 197, 134, 244, 186, 10, 0, 7, 1, 7, 100, 101, 102, 97, 117, 108, 116, 3, 9, 112, 97, 114, 97, 103, 114, 97, 112, 104, 7, 0, 197, 134, 244, 186, 10, 0, 6, 4, 0, 197, 134, 244, 186, 10, 1, 1, 115, 0],
 [1, 1, 197, 134, 244, 186, 10, 3, 132, 197, 134, 244, 186, 10, 2, 3, 227, 129, 149, 1, 197, 134, 244, 186, 10, 1, 2, 1],
 [1, 4, 197, 134, 244, 186, 10, 0, 7, 1, 7, 100, 101, 102, 97, 117, 108, 116, 3, 9, 112, 97, 114, 97, 103, 114, 97, 112, 104, 7, 0, 197, 134, 244, 186, 10, 0, 6, 1, 0, 197, 134, 244, 186, 10, 1, 1, 132, 197, 134, 244, 186, 10, 2, 3, 227, 129, 149, 1, 197, 134, 244, 186, 10, 1, 2, 1],
 [1, 1, 197, 134, 244, 186, 10, 4, 132, 197, 134, 244, 186, 10, 3, 1, 120, 0],
 [1, 1, 197, 134, 244, 186, 10, 5, 132, 197, 134, 244, 186, 10, 4, 3, 227, 129, 129, 1, 197, 134, 244, 186, 10, 1, 4, 1],
 [1, 1, 197, 134, 244, 186, 10, 6, 132, 197, 134, 244, 186, 10, 5, 1, 107, 0],
 [1, 2, 197, 134, 244, 186, 10, 4, 129, 197, 134, 244, 186, 10, 3, 1, 132, 197, 134, 244, 186, 10, 4, 3, 227, 129, 129, 1, 197, 134, 244, 186, 10, 1, 4, 1],
 [1, 1, 197, 134, 244, 186, 10, 7, 132, 197, 134, 244, 186, 10, 6, 3, 227, 129, 147, 1, 197, 134, 244, 186, 10, 1, 6, 1],
 [1, 2, 197, 134, 244, 186, 10, 6, 129, 197, 134, 244, 186, 10, 5, 1, 132, 197, 134, 244, 186, 10, 6, 3, 227, 129, 147, 1, 197, 134, 244, 186, 10, 1, 6, 1],
 [1, 1, 197, 134, 244, 186, 10, 8, 132, 197, 134, 244, 186, 10, 7, 1, 114, 0],
 [1, 1, 197, 134, 244, 186, 10, 9, 132, 197, 134, 244, 186, 10, 8, 3, 227, 130, 140, 1, 197, 134, 244, 186, 10, 1, 8, 1],
 [1, 1, 197, 134, 244, 186, 10, 8, 132, 197, 134, 244, 186, 10, 7, 1, 114, 0],
 [1, 1, 197, 134, 244, 186, 10, 10, 132, 197, 134, 244, 186, 10, 9, 1, 107, 0],
 [1, 1, 197, 134, 244, 186, 10, 11, 132, 197, 134, 244, 186, 10, 10, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 10, 1],
 [1, 1, 197, 134, 244, 186, 10, 12, 132, 197, 134, 244, 186, 10, 11, 1, 114, 0],
 [1, 1, 197, 134, 244, 186, 10, 13, 132, 197, 134, 244, 186, 10, 12, 3, 227, 130, 137, 1, 197, 134, 244, 186, 10, 1, 12, 1],
 [1, 1, 197, 134, 244, 186, 10, 9, 132, 197, 134, 244, 186, 10, 8, 3, 227, 130, 140, 1, 197, 134, 244, 186, 10, 1, 8, 1],
 [1, 1, 197, 134, 244, 186, 10, 10, 132, 197, 134, 244, 186, 10, 9, 1, 107, 0],
 [1, 1, 197, 134, 244, 186, 10, 11, 132, 197, 134, 244, 186, 10, 10, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 10, 1],
 [1, 1, 197, 134, 244, 186, 10, 12, 132, 197, 134, 244, 186, 10, 11, 1, 114, 0],
 [1, 1, 197, 134, 244, 186, 10, 14, 132, 197, 134, 244, 186, 10, 13, 1, 98, 0],
 [1, 1, 197, 134, 244, 186, 10, 16, 132, 197, 134, 244, 186, 10, 15, 1, 103, 0],
 [1, 1, 197, 134, 244, 186, 10, 15, 132, 197, 134, 244, 186, 10, 14, 3, 227, 129, 176, 1, 197, 134, 244, 186, 10, 1, 14, 1],
 [1, 1, 197, 134, 244, 186, 10, 17, 132, 197, 134, 244, 186, 10, 16, 3, 227, 129, 144, 1, 197, 134, 244, 186, 10, 1, 16, 1],
 [1, 1, 197, 134, 244, 186, 10, 17, 132, 197, 134, 244, 186, 10, 16, 3, 227, 129, 144, 1, 197, 134, 244, 186, 10, 1, 16, 1],
 [1, 1, 197, 134, 244, 186, 10, 18, 132, 197, 134, 244, 186, 10, 17, 6, 227, 131, 144, 227, 130, 176, 1, 197, 134, 244, 186, 10, 2, 15, 1, 17, 1],
 [1, 1, 197, 134, 244, 186, 10, 20, 132, 197, 134, 244, 186, 10, 19, 1, 103, 0],
 [1, 3, 197, 134, 244, 186, 10, 13, 132, 197, 134, 244, 186, 10, 12, 3, 227, 130, 137, 129, 197, 134, 244, 186, 10, 13, 1, 132, 197, 134, 244, 186, 10, 14, 4, 227, 129, 176, 103, 1, 197, 134, 244, 186, 10, 2, 12, 1, 14, 1],
 [1, 1, 197, 134, 244, 186, 10, 21, 132, 197, 134, 244, 186, 10, 20, 3, 227, 129, 140, 1, 197, 134, 244, 186, 10, 1, 20, 1],
 [1, 1, 197, 134, 244, 186, 10, 23, 132, 197, 134, 244, 186, 10, 22, 3, 227, 129, 170, 1, 197, 134, 244, 186, 10, 1, 22, 1],
 [1, 3, 197, 134, 244, 186, 10, 18, 132, 197, 134, 244, 186, 10, 17, 6, 227, 131, 144, 227, 130, 176, 129, 197, 134, 244, 186, 10, 19, 1, 132, 197, 134, 244, 186, 10, 20, 3, 227, 129, 140, 1, 197, 134, 244, 186, 10, 3, 15, 1, 17, 1, 20, 1],
 [1, 1, 197, 134, 244, 186, 10, 24, 132, 197, 134, 244, 186, 10, 23, 3, 227, 129, 132, 0],
 [1, 1, 197, 134, 244, 186, 10, 22, 132, 197, 134, 244, 186, 10, 21, 1, 110, 0],
 [1, 1, 197, 134, 244, 186, 10, 26, 132, 197, 134, 244, 186, 10, 25, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 25, 1],
 [1, 1, 197, 134, 244, 186, 10, 25, 132, 197, 134, 244, 186, 10, 24, 1, 107, 0],
 [1, 4, 197, 134, 244, 186, 10, 22, 129, 197, 134, 244, 186, 10, 21, 1, 132, 197, 134, 244, 186, 10, 22, 6, 227, 129, 170, 227, 129, 132, 129, 197, 134, 244, 186, 10, 24, 1, 132, 197, 134, 244, 186, 10, 25, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 2, 22, 1, 25, 1],
 [1, 1, 197, 134, 244, 186, 10, 27, 132, 197, 134, 244, 186, 10, 26, 1, 100, 0],
 [1, 1, 197, 134, 244, 186, 10, 28, 132, 197, 134, 244, 186, 10, 27, 3, 227, 129, 169, 1, 197, 134, 244, 186, 10, 1, 27, 1],
 [1, 2, 197, 134, 244, 186, 10, 27, 129, 197, 134, 244, 186, 10, 26, 1, 132, 197, 134, 244, 186, 10, 27, 3, 227, 129, 169, 1, 197, 134, 244, 186, 10, 1, 27, 1],
 [1, 1, 197, 134, 244, 186, 10, 29, 132, 197, 134, 244, 186, 10, 28, 3, 227, 129, 134, 0],
 [1, 1, 197, 134, 244, 186, 10, 30, 132, 197, 134, 244, 186, 10, 29, 1, 107, 0],
 [1, 1, 197, 134, 244, 186, 10, 29, 132, 197, 134, 244, 186, 10, 28, 3, 227, 129, 134, 0],
 [1, 1, 197, 134, 244, 186, 10, 31, 132, 197, 134, 244, 186, 10, 30, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 30, 1],
 [1, 1, 197, 134, 244, 186, 10, 30, 132, 197, 134, 244, 186, 10, 29, 1, 107, 0],
 [1, 1, 197, 134, 244, 186, 10, 31, 132, 197, 134, 244, 186, 10, 30, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 30, 1],
 [1, 1, 197, 134, 244, 186, 10, 32, 135, 197, 134, 244, 186, 10, 0, 3, 9, 112, 97, 114, 97, 103, 114, 97, 112, 104, 0],
 [1, 1, 197, 134, 244, 186, 10, 32, 135, 197, 134, 244, 186, 10, 0, 3, 9, 112, 97, 114, 97, 103, 114, 97, 112, 104, 0],
 [1, 2, 197, 134, 244, 186, 10, 33, 7, 0, 197, 134, 244, 186, 10, 32, 6, 4, 0, 197, 134, 244, 186, 10, 33, 1, 107, 0],
 [1, 1, 197, 134, 244, 186, 10, 35, 132, 197, 134, 244, 186, 10, 34, 3, 227, 129, 139, 1, 197, 134, 244, 186, 10, 1, 34, 1],
 [1, 1, 197, 134, 244, 186, 10, 36, 132, 197, 134, 244, 186, 10, 35, 1, 107, 0]]

maybe It's related to this issue?
Let me know if there's anything I can help with it.

Thanks!

XMLElement children manipulation randomly breaks

Problem

Manipulating an XMLElement randomly breaks (observed in flaky tests). It is possible that the manipulation isn't done properly on the Ruby side or that we have some memory mapping issues between Ruby and Rust.

Examples

Failures:

  1) Y::XMLElement when changing commits automatically
     Failure/Error: expect(changes[0].first[:added].map(&:tag)).to match_array(%w[A B C])

       expected collection contained:  ["A", "B", "C"]
       actual collection contained:    ["\u0000", "A", "C"]
       the missing elements were:      ["B"]
       the extra elements were:        ["\u0000"]
     # ./spec/y/yxml_element_spec.rb:324:in `block (3 levels) in <top (required)>'

Job: https://github.com/y-crdt/yrb/actions/runs/3234322746/jobs/5297285225

Failures:

  1) Y::XMLElement when changing commits automatically
     Failure/Error: expect(changes[0].first[:added].map(&:tag)).to match_array(%w[A B C])

       expected collection contained:  ["A", "B", "C"]
       actual collection contained:    ["\n", "A", "C"]
       the missing elements were:      ["B"]
       the extra elements were:        ["\n"]
     # ./spec/y/xml_element_spec.rb:324:in `block (3 levels) in <top (required)>'

Job: https://github.com/y-crdt/yrb/actions/runs/3287990605/jobs/5417793161

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/hannesmoser/.cargo/registry/src/github.com-1ecc6299db9ec823/yrs-0.12.0/src/types/xml.rs:110:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

fatal: called `Option::unwrap()` on a `None` value

  0) Y::XMLElement when changing commits automatically
     Failure/Error: yxml_element_tag

     fatal:
       called `Option::unwrap()` on a `None` value
     # ./lib/y/xml.rb:237:in `yxml_element_tag'
     # ./lib/y/xml.rb:237:in `tag'
     # ./spec/y/xml_element_spec.rb:320:in `map'
     # ./spec/y/xml_element_spec.rb:320:in `block (3 levels) in <top (required)>'

Analysis

For whatever reason, some of the (XML) elements that are forwarded to Ruby are no longer in memory when we access them. The container is there Y::XMLElement, but when accessing the tag, we get a different set of errors.

pub fn tag(&self) -> &str {
  let inner = &self.0 .0;
  inner.name.as_ref().unwrap()
}

When I add GC.start after the observer is attached, I can reliably produce the issues. I think this confirms that the elements emitted by change events are no longer accessible due to being garbage collected.

# garbage collect immediately
GC.start

There is some documentation about this in magnus. We are required to keep values on the stack, and I think it is impossible, because if we delete an element, it actually gets removed from the CRDT, and we just pass it to the callback and eventually access it later on. In other words, in order for the observer pattern to work, I need to control garbage collection ๐Ÿคท.
https://github.com/matsadler/magnus#safety

Defining a Class#new singelton method causes issues with inheritance

Some y-rb object constructors are defined by the Class#new method. This causes some troubles when using common inheritance patterns:

class MyAwareness < Y::Awareness
  # need to explicitly define new as the defined singelton method does not expect any arguments
  self.new(argument)
    โ€ฆ
  end
end

Instead of declaring #new, we want o just create a regular #initializer method. But, if the new constructor takes an argument and the parent class constructor does not, we end up with an error.

Accessing attributes of Y::Text inside ruby

Hello,

First place, amazing project you've got!

I am using yrb with rails, alongside quill and yquill on my frontend.

I have customized some attributes of quill to generate custom html formats inside my editor via Blocks.

However yquill serializes all the data into Y::Text and sends it to the WebSocket. On my rails backend on the other hand, If I try to access the attributes of Y::Text it doesn't give me the option at all (e.g.: if I wanted to generate a PDF for download in my backend, I would have no way to access the attributes of the custom quill format I created).

Steps you can take to reproduce:

ydoc = Y::Doc.new
text = ydoc.get_text("quill")
ydoc.transact do
  text << "Hello"
  text.format(0, 4, {CustomTheme: "Format01"})
end

now the text object has no accessor method to lookup the format I just set.

From the original docs, there is a way to at least recover it by iterating over the deltas: https://docs.yjs.dev/api/shared-types/y.text

The only way I found so far with yrb is to somehow observe the mutations as they happen. However this is not a solid plan as this would grow exponentially due to the amount of documents on my system.

Is there way good way to retrieve the formats for a text object? If there isn't and it requires implementation, I'd be more than glad to help implement it (just need a little guidance).

Build errors on 0.5.1

When attempting to install this gem in my rails application, I am getting an error while installing with native extensions. I have installed clang:

root@2dea80f87d08:/app# clang --version
Debian clang version 11.0.1-2
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

And am running ruby 3.1 with RubyGems 3.4:

root@2dea80f87d08:/app# ruby --version
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [aarch64-linux]
root@2dea80f87d08:/app# rubygems
bash: rubygems: command not found
root@2dea80f87d08:/app# gem --version
3.4.15

Adding the gem to my gemfile and running bundle install results in a rust build error:

Compiling yrb v0.5.1 (/bundle/ruby/3.1.0/gems/y-rb-0.5.1/ext/yrb)
error[E0603]: struct `Subscription` is private
  --> src/yawareness.rs:5:60
   |
5  | use y_sync::awareness::{Awareness, AwarenessUpdate, Event, Subscription};
   |                                                            ^^^^^^^^^^^^ private struct
   |
note: the struct `Subscription` is defined here
  --> /bundle/ruby/3.1.0/gems/y-rb-0.5.1/ext/yrb/.rb-sys/stable/cargo/registry/src/index.crates.io-6f17d22bba15001f/y-sync-0.3.1/src/awareness.rs:10:26
   |
10 | use yrs::{Doc, Observer, Subscription};
   |                          ^^^^^^^^^^^^

error[E0308]: mismatched types
  --> src/utils.rs:24:18
   |
24 |         a.insert(k, v);
   |           ------ ^ expected `Arc<str>`, found `Rc<_>`
   |           |
   |           arguments to this method are incorrect
   |
   = note: expected struct `Arc<str>`
              found struct `Rc<_>`
note: method defined here
  --> /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/collections/hash/map.rs:1103:12

error[E0308]: mismatched types
  --> src/yattrs.rs:26:30
   |
26 |                 attrs.insert(Rc::from(k), avalue);
   |                       ------ ^^^^^^^^^^^ expected `Arc<str>`, found `Rc<_>`
   |                       |
   |                       arguments to this method are incorrect
   |
   = note: expected struct `Arc<str>`
              found struct `Rc<_>`
note: method defined here
  --> /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/collections/hash/map.rs:1103:12

error[E0308]: mismatched types
  --> src/yawareness.rs:69:38
   |
69 |         YAwarenessSubscription::from(subscription)
   |         ---------------------------- ^^^^^^^^^^^^ expected `YAwarenessSubscription`, found `Subscription<Arc<dyn Fn(..., ...)>>`
   |         |
   |         arguments to this function are incorrect
   |
   = note: expected struct `YAwarenessSubscription`
              found struct `Subscription<Arc<(dyn for<'a, 'b> Fn(&'a y_sync::awareness::Awareness, &'b y_sync::awareness::Event) + 'static)>>`
note: associated function defined here
  --> /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/convert/mod.rs:548:8
help: try wrapping the expression in `yawareness::YAwarenessSubscription`
   |
69 |         YAwarenessSubscription::from(yawareness::YAwarenessSubscription(subscription))
   |                                      +++++++++++++++++++++++++++++++++++            +

Some errors have detailed explanations: E0308, E0603.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `yrb` (lib) due to 4 previous errors
make: *** [Makefile:555: target/release/libyrb.so] Error 101

make failed, exit code 2

I'm not sure why this is attempting to build with native extensions in the first place, as far as I'm aware there should be an included binary for my setup. In any case, it seems as though I've installed all the dependencies, but am still unable to build, a use-case which ought to work.

Implement better Hash iterators

#134 surfaced a limitation of the Y::Map implementation. It should support more hash iterator methods. The semantics of that API are currently unclear and do not always match common Ruby Hash-like access patterns.

Make y-rb thread-safe

Problem

y-rb is not thread-safe. Originally I thought there are no use cases where concurrency patterns need to be supported, but it is relatively easy to shoot yourself into the foot when using y-rb with ActionCable in Rails. In particular, the combination of update events (attach(โ€ฆ)) with worker pools cause some issues (I get segfaults here and then).

To do

Update build instructions

The instructions in README are not working for me; I was on Ruby 3.0.5, which ships rubygems 3.2.33. rubygems is an stdlib gem bundled with the Ruby platform: https://stdgems.org/rubygems/

[9:34:53] work/yrb::main โœ” bundle install
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Could not find compatible versions

Because every version of y-rb depends on RubyGems >= 3.3.21
  and Gemfile depends on y-rb >= 0,
  RubyGems >= 3.3.21 is required.
So, because current RubyGems version is = 3.2.33,
  version solving has failed.

The docs currently mention to manually update rubygems to 3.3.x via gem system --update but this command does not seem to exist:

[9:38:21] work/yrb::main โœ” gem system --update  
ERROR:  While executing gem ... (Gem::UnknownCommandError)
    Unknown command system

What I did instead is to switch my shell Ruby to 3.1+ which bundles the necessary version of rubygems (3.3.x).

I am not sure whether or how one should update rubygems beyond the version shipped with Ruby itself; should we instead document the minimum Ruby to be 3.1, which ships with rubygems 3.3.3 by default? That fixes the build problems for me, but of course that would imply older Rubies are not supported. This may be OK, considering that the 3.0 line of Rubies will reach EOL in about a year from now: https://endoflife.date/ruby

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.