Skip to content

Commit

Permalink
Improve Rust connect example readability
Browse files Browse the repository at this point in the history
  • Loading branch information
rushmorem authored Oct 9, 2024
1 parent e69635e commit a8a476a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/content/doc-sdk-rust/methods/connect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,23 @@ The `.connect()` method will usually take a `String` or a type that implements `
where T: Into<String>`.

```rust
use std::sync::LazyLock;
use std::time::Duration;
use surrealdb::engine::remote::ws::{Client, Ws, Wss};
use surrealdb::opt::Config;
use surrealdb::Surreal;

static DB: LazyLock<Surreal<Client>> = LazyLock::new(Surreal::init);

#[tokio::main]
async fn main() -> surrealdb::Result<()> {
let db: Surreal<Client> = Surreal::init();
// Connect to a local endpoint
db.connect::<Ws>("127.0.0.1:8000").await?;
DB.connect::<Ws>("127.0.0.1:8000").await?;
// Connect to a remote endpoint
db.connect::<Wss>("cloud.surrealdb.com").await?;
DB.connect::<Wss>("cloud.surrealdb.com").await?;
// A tuple with a Config struct can also be passed in for fine tuning of the connection
db.connect::<Ws>((
"127.0.0.1:8000",
Config::default().query_timeout(Duration::from_millis(1500)),
))
.await?;
let config = Config::default().query_timeout(Duration::from_millis(1500));
DB.connect::<Ws>(("127.0.0.1:8000", config)).await?;
Ok(())
}
```
```

0 comments on commit a8a476a

Please sign in to comment.