Skip to content

Commit

Permalink
Merge pull request jonhoo#154 from stevepryde/minimal-mut
Browse files Browse the repository at this point in the history
Make access to self immutable where possible
  • Loading branch information
jonhoo authored Feb 10, 2022
2 parents 0314cf8 + 2325779 commit db3de7a
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 259 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use fantoccini::{Client, Locator};
// let's set up the sequence of steps we want the browser to take
#[tokio::main]
async fn main() -> Result<(), fantoccini::error::CmdError> {
let mut c = Client::new("http://localhost:4444").await.expect("failed to connect to WebDriver");
let c = Client::new("http://localhost:4444").await.expect("failed to connect to WebDriver");

// first, go to the Wikipedia page for Foobar
c.goto("https://en.wikipedia.org/wiki/Foobar").await?;
Expand Down Expand Up @@ -62,7 +62,7 @@ Let's make the program do that for us instead:
// go to the Wikipedia frontpage this time
c.goto("https://www.wikipedia.org/").await?;
// find the search form, fill it out, and submit it
let mut f = c.form(Locator::Css("#search-form")).await?;
let f = c.form(Locator::Css("#search-form")).await?;
f.set_by_name("search", "foobar").await?
.submit().await?;

Expand All @@ -80,7 +80,7 @@ What if we want to download a raw file? Fantoccini has you covered:
// go back to the frontpage
c.goto("https://www.wikipedia.org/").await?;
// find the source for the Wikipedia globe
let mut img = c.find(Locator::Css("img.central-featured-logo")).await?;
let img = c.find(Locator::Css("img.central-featured-logo")).await?;
let src = img.attr("src").await?.expect("image should have a src");
// now build a raw HTTP client request (which also has all current cookies)
let raw = img.client().raw_client_for(fantoccini::Method::GET, &src).await?;
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to webdriver instance that is listening on port 4444
let mut client = ClientBuilder::native()
let client = ClientBuilder::native()
.connect("http://localhost:4444")
.await?;

Expand All @@ -51,7 +51,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
button.click().await?;

// Find the big textarea.
let mut code_area = client
let code_area = client
.wait()
.for_element(Locator::Css(".ace_text-input"))
.await?;
Expand Down
2 changes: 1 addition & 1 deletion examples/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to webdriver instance that is listening on port 4444
let mut client = ClientBuilder::native()
let client = ClientBuilder::native()
.connect("http://localhost:4444")
.await?;

Expand Down
146 changes: 61 additions & 85 deletions src/client.rs

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Client {
///
/// See [16.1 Get All Cookies](https://www.w3.org/TR/webdriver1/#get-all-cookies) of the
/// WebDriver standard.
pub async fn get_all_cookies(&mut self) -> Result<Vec<Cookie<'static>>, error::CmdError> {
pub async fn get_all_cookies(&self) -> Result<Vec<Cookie<'static>>, error::CmdError> {
let resp = self.issue(WebDriverCommand::GetCookies).await?;

let webdriver_cookies: Vec<WebDriverCookie> = serde_json::from_value(resp)?;
Expand All @@ -152,10 +152,7 @@ impl Client {
///
/// See [16.2 Get Named Cookie](https://www.w3.org/TR/webdriver1/#get-named-cookie) of the
/// WebDriver standard.
pub async fn get_named_cookie(
&mut self,
name: &str,
) -> Result<Cookie<'static>, error::CmdError> {
pub async fn get_named_cookie(&self, name: &str) -> Result<Cookie<'static>, error::CmdError> {
let resp = self
.issue(WebDriverCommand::GetNamedCookie(name.to_string()))
.await?;
Expand All @@ -167,7 +164,7 @@ impl Client {
///
/// See [16.3 Add Cookie](https://www.w3.org/TR/webdriver1/#add-cookie) of the
/// WebDriver standard.
pub async fn add_cookie(&mut self, cookie: Cookie<'static>) -> Result<(), error::CmdError> {
pub async fn add_cookie(&self, cookie: Cookie<'static>) -> Result<(), error::CmdError> {
let webdriver_cookie: WebDriverCookie = cookie.into();
self.issue(WebDriverCommand::AddCookie(webdriver_cookie.into_params()))
.await?;
Expand All @@ -178,7 +175,7 @@ impl Client {
///
/// See [16.4 Delete Cookie](https://www.w3.org/TR/webdriver1/#delete-cookie) of the
/// WebDriver standard.
pub async fn delete_cookie(&mut self, name: &str) -> Result<(), error::CmdError> {
pub async fn delete_cookie(&self, name: &str) -> Result<(), error::CmdError> {
self.issue(WebDriverCommand::DeleteCookie(name.to_string()))
.await
.map(|_| ())
Expand All @@ -188,7 +185,7 @@ impl Client {
///
/// See [16.5 Delete All Cookies](https://www.w3.org/TR/webdriver1/#delete-all-cookies) of the
/// WebDriver standard.
pub async fn delete_all_cookies(&mut self) -> Result<(), error::CmdError> {
pub async fn delete_all_cookies(&self) -> Result<(), error::CmdError> {
self.issue(WebDriverCommand::DeleteCookies)
.await
.map(|_| ())
Expand Down
Loading

0 comments on commit db3de7a

Please sign in to comment.