How to get value from match?


Hello everyone,I have a function that handles the parameters passed by the match. If the received parameter conforms to the CASS_VALUE_TYPE_INT type, I want to take the i of info!("{:?}", i); and use it as the return value. What should I do?

Complete code

The following is a simple code:

 unsafe fn print_value(items_number_value : *const CassValue_) {
        match cass_value_is_null(items_number_value) {
            cass_false => {
                match cass_value_type(items_number_value) {
                    CASS_VALUE_TYPE_TEXT |
                    CASS_VALUE_TYPE_ASCII |
                    CASS_VALUE_TYPE_VARCHAR => {
                        let mut text = mem::zeroed();
                        let mut text_length = mem::zeroed();
                        cass_value_get_string(items_number_value, &mut text, &mut text_length);
                        debug!("Value Type => {:?}", cass_value_type(items_number_value));
                        info!("\"{:?}\" ", raw2utf8(text, text_length));
                    CASS_VALUE_TYPE_BIGINT => {
                        let mut i = mem::zeroed();
                        cass_value_get_int64(items_number_value, &mut i);
                        debug!("Value Type => {:?}", cass_value_type(items_number_value));
                        info!("{:?} ", i);
                    CASS_VALUE_TYPE_INT => {
                        let mut i = mem::zeroed();
                        cass_value_get_int32(items_number_value, &mut i);
                        debug!("Value Type => {:?}", cass_value_type(items_number_value));
                        info!("{:?}", i);
                    _ => error!("Error"),
            cass_true => error!("<null>"),

P.S:The purpose of taking out the value of i is to display it on the web page.


match arms all need to have the same return type. One way to handle this is to return an enum with different variants, but that generally leads to more match statements later on.

This might be a clue, this match could return a HTML element (or other formatted content) ready for interpolation in the output


Use enum to solve it? Because the format of the query is fixed.

But, the cassandra value is in lib and it is already enum.

pub enum CassValueType_ {

So, if you use the return method, can you get the value of the query?

Moreover, the main purpose is to transfer the value of the query to the web (using iron), I have not found a similar way of using…


you’re already using an info! macro to print the content, my point is that you could have each match arm return the formatted HTML appropriate for each type (as a String, or as some HTML element structure, depending on what suits your context). That way all the arms have the same expression result type.


Finally, I used global variables to solve the problem temporarily.