//! Builds a document in Rust and writes a v1 update to stdout, so the JS //! side can verify it reads what Rust writes. This is the direction Task 3 //! cannot test: a Rust implementation that reads JS updates but writes //! something JS cannot read would have passed Task 3 completely. use std::io::Write; use yrs::types::Attrs; use yrs::{Doc, Options, ReadTxn, Text, Transact}; fn main() { // Both values fixed: never drawn from yrs (Global Constraints -- see // core/src/lib.rs and clippy.toml, which bans the alternatives that draw // entropy). let guid: yrs::Uuid = "emit-update-guid".into(); let doc = Doc::with_options(Options::with_guid_and_client_id(guid, 7001)); { let text = doc.get_or_insert_text("content"); let mut txn = doc.transact_mut(); text.insert(&mut txn, 0, "from rust 🦀 café"); // Format part of the inserted text so the emitted update carries // real formatting bytes, not just plain-text inserts. A plain-text // check alone cannot distinguish a correct implementation from one // that dropped formatting (see fixtures/verify-rust.mjs). let attrs: Attrs = Attrs::from([("bold".into(), true.into())]); text.format(&mut txn, 5, 4, attrs); } let txn = doc.transact(); let update = txn.encode_state_as_update_v1(&yrs::StateVector::default()); std::io::stdout().write_all(&update).unwrap(); }