mirror of
https://github.com/zap-proto/rust.git
synced 2026-10-30 15:04:23 +00:00
Two pre-existing CI failures (unrelated to codegen/install-zap): - minrust 1.81: quickcheck 1.1.0 pulls rand 0.10 -> rand_core 0.10.1, whose Cargo.toml requires the edition2024 feature (unstable on Cargo 1.81). Pin quickcheck to =1.0.3 (last version on rand 0.8 / rand_core 0.6.4) — within MSRV, no major bump. Fresh-resolve verified: rand_core 0.10.1 leaves the graph. - formatting: ran 'cargo +nightly fmt --all'; the CI check (--check --unstable-features --error-on-unformatted, nightly) now passes.
73 lines
2.8 KiB
Rust
73 lines
2.8 KiB
Rust
// Copyright (c) 2013-2016 Sandstorm Development Group, Inc. and contributors
|
|
// Licensed under the MIT License:
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
use crate::hello_world_zap::hello_world;
|
|
use std::net::ToSocketAddrs;
|
|
use zap_rpc::{rpc_twoparty_zap, twoparty, RpcSystem};
|
|
|
|
use futures::AsyncReadExt;
|
|
|
|
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let args: Vec<String> = ::std::env::args().collect();
|
|
if args.len() != 4 {
|
|
println!("usage: {} client HOST:PORT MESSAGE", args[0]);
|
|
return Ok(());
|
|
}
|
|
|
|
let addr = args[2]
|
|
.to_socket_addrs()?
|
|
.next()
|
|
.expect("could not parse address");
|
|
|
|
let msg = args[3].to_string();
|
|
|
|
tokio::task::LocalSet::new()
|
|
.run_until(async move {
|
|
let stream = tokio::net::TcpStream::connect(&addr).await?;
|
|
stream.set_nodelay(true)?;
|
|
let (reader, writer) =
|
|
tokio_util::compat::TokioAsyncReadCompatExt::compat(stream).split();
|
|
let rpc_network = Box::new(twoparty::VatNetwork::new(
|
|
futures::io::BufReader::new(reader),
|
|
futures::io::BufWriter::new(writer),
|
|
rpc_twoparty_zap::Side::Client,
|
|
Default::default(),
|
|
));
|
|
let mut rpc_system = RpcSystem::new(rpc_network, None);
|
|
let hello_world: hello_world::Client =
|
|
rpc_system.bootstrap(rpc_twoparty_zap::Side::Server);
|
|
|
|
tokio::task::spawn_local(rpc_system);
|
|
|
|
let mut request = hello_world.say_hello_request();
|
|
request.get().init_request().set_name(&msg[..]);
|
|
|
|
let reply = request.send().promise.await?;
|
|
|
|
println!(
|
|
"received: {}",
|
|
reply.get()?.get_reply()?.get_message()?.to_str()?
|
|
);
|
|
Ok(())
|
|
})
|
|
.await
|
|
}
|