Giter VIP home page Giter VIP logo

serde-xmlrpc's Introduction

serde-xmlrpc

Build Status Crates.io Docs

This library is meant to be a simple XMLRPC library with the minimal support needed to build out applications using XMLRPC. No additional parsing, no transports, etc.

Breaking Changes

v0.3.0

  • value_from_str changed to return T where T: serde::de::Deserialize<'a>
  • value_to_string changed to take T where T: serde::ser::Serialize
  • request_to_string changed to take an impl Iterator<Item = Value>
  • Structs changed to only allow string types as keys
  • Drop DecodingError::UnexpectedError variant
  • Impl serde::Deserialize directly on Value rather than through a wrapper type

v0.2.0

  • response_from_str changed to take an impl Iterator<Item = Value>

serde-xmlrpc's People

Contributors

belak avatar blaenk avatar carter12s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

serde-xmlrpc's Issues

Response From String

I have been running into issues wrapping response_from_str() in a generic method. Below is my attempt:

Example
fn send<'a, U, T>(self, url: U) -> Result<T, CustomError>
where
    U: IntoUrl,
    T: Deserialize<'a>
{
    let body = request_to_string(self.method.as_ref(), self.args)?;
    let resp = reqwest::blocking::Client::new() 
        .post(url)
        .body(body)
        .send()?
        .text()?;
    Ok(response_from_str::<T>(&resp)?)
}

The issue is that this method expects a &str argument, but I can't get the argument to outlive the method. Below is the error:

Error
error[E0597]: `resp` does not live long enough
  --> src/lib.rs:45:35
   |
34 |     fn send<'a, U, T>(self, url: U) -> Result<T, RequestError>
   |             -- lifetime `'a` defined here
...
40 |         let resp = reqwest::blocking::Client::new() 
   |             ---- binding `resp` declared here
...
45 |         Ok(response_from_str::<T>(&resp)?)
   |            -----------------------^^^^^-
   |            |                      |
   |            |                      borrowed value does not live long enough
   |            argument requires that `resp` is borrowed for `'a`
46 |     }
   |     - `resp` dropped here while still borrowed

If I change the signature of response_from_str() to accept String (see Diff below), it works. Would you be open to a PR to this effect, or is there a better way you recommend going about this? Thanks!

Diff
diff --git a/src/lib.rs b/src/lib.rs
index 2b7915d..456b09c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -26,11 +26,11 @@ pub use value::{to_value, Value};
 ///
 /// assert_eq!(val, "hello world".to_string());
 /// ```
-pub fn response_from_str<'a, T>(input: &'a str) -> Result<T>
+pub fn response_from_str<'a, T>(input: String) -> Result<T>
 where
     T: serde::de::Deserialize<'a>,
 {
-    let mut reader = Reader::from_str(input);
+    let mut reader = Reader::from_str(input.as_str());
     reader.expand_empty_elements(true);
     reader.trim_text(true);
 
@@ -460,7 +460,7 @@ mod tests {
                  </struct>
                 </value>
               </fault>
-            </methodResponse>"#,
+            </methodResponse>"#.to_string(),
         )
         .unwrap_err();
 
@@ -487,7 +487,7 @@ mod tests {
               <params>
                 <param><value><string>hello world</string></value></param>
               </params>
-            </methodResponse>"#,
+            </methodResponse>"#.to_string(),
         )
         .unwrap();

Would pull requests implementing request parsing be accepted and published?

Heyo, I'm working on adding native ROS1 support to roslibrust. The requires the ability to both make xmlrpc calls and to run an xmlrpc server which responds to requests.

I've had great success using this crate for making requests, but realize it doesn't have functionality for parsing a request as you'd want to on the server side. After looking at the other xmlrpc implementations available for Rust, I think I'd prefer to add that functionality to this crate rather than switch to any of the others.

This repo seems fairly inactive since 2020, and I'd prefer to not publish yet another xmlrpc crate variant, but to expand this one. So my main question is: is maintenance of this crate active enough that If I made some substantial PRs the could be merged and published in relatively short time?

Would offer to join as a maintainer of this repo / crate if that is an option?

Relicense under Apache 2.0 + MIT

It probably makes sense to re-license this to be more in line with usual best practices in the Rust community. I meant to do this earlier, but never got around to it.

Even though it would probably be OK to just change it, because we now have additional contributors, to be safe I'm looking for permission to relicense.

CC @Carter12s @blaenk

[Bug] deserialization from value into Option fails

Given code:

#[derive(Deserialize, Serialize)]
pub struct LoginToReturnFromXMLRPC {
#[serde(rename = "avatarName")]
username: String,
pub email: String,
#[serde(rename = "userId")]
pub user_id: u32,
#[serde(rename = "securityKey")]
pub security_key: String,
// Skip deserializing this field if it's None
pub device_login_token: Option,
}

See device_login_token. Might be nil might not be. That's why I gave it an Option. if it's some then the decoder in serdexml_rpc will give out the following error.

Error: Bug: serde: invalid type: string "3026b5dafa5aae3210096e30649ff31c", expected option.

So the library basically doesn't turn it into an Option if it's already a string.

Clean up error handling

There are quite a few different error variants when it should probably just be 2 or 3. This should be cleaned up before the 0.2.0 release.

Quick-xml API has changed a lot... and overdue for update

In attempting to modernize all the deps this crate uses I tried to rev quick-xml to its latest version.

There were a LOT of errors. Started solving a few of them, but many turned hairy quickly and didn't have obvious answers to me. Would be good to try to take a stab at modernizing, but since we don't leak this dependency there isn't huge call for this. Would be a nice to have to get on latest version.

Serializing structs as parameters/values

It is not clear to me how to serialize structs as parameters to request. In particular I seem to be missing a step to convert the struct to a BTreeMap which then in turn can be used as a Value.

Here is an example of what I want to archive:

use serde::Serialize;
use serde_xmlrpc::{request_to_string, Value};

fn main() {
    let param = Custom {
        field: 42
    };

    let request = request_to_string("example", vec![
        Value::from(param) // Error (see below)
    ]).unwrap();
}

#[derive(Serialize)]
struct Custom {
    field: i32,
}

This code fails to compile with the following error message:

error[E0277]: the trait bound `Value: From<Custom>` is not satisfied
  --> src/bin/serde-xmlrpc-structs-as-value.rs:10:9
   |
10 |         Value::from(param)
   |         ^^^^^^^^^^^ the trait `From<Custom>` is not implemented for `Value`
   |
   = help: the following implementations were found:
             <Value as From<&str>>
             <Value as From<BTreeMap<std::string::String, Value>>>
             <Value as From<Vec<Value>>>
             <Value as From<Vec<u8>>>
           and 6 others
   = note: required by `std::convert::From::from`

Whereas the "opposite" operation, de-serializing the struct from a response works just fine:

use serde::Deserialize;
use serde_xmlrpc::response_from_str;

fn main() {
    let resp: Custom = response_from_str(
        "<methodResponse>
                <params>
                    <param>
                        <value>
                            <struct>
                                <member>
                                    <name>field</name>
                                    <value><int>42</int></value>
                                </member>
                            </struct>
                        </value>
                    </param>
                </params>
              </methodResponse>").unwrap();
    println!("{:?}", resp);
}

#[derive(Deserialize, Debug)]
struct Custom {
    field: i32,
}

I might be just missing something obvious here. Is there any way I can serialize a struct as a Value/parameter in a request?

Thanks!

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.