@@ -1823,170 +1823,4 @@ impl Request {
18231823 pub fn is_disable_keep_alive ( & self ) -> bool {
18241824 !self . is_enable_keep_alive ( )
18251825 }
1826-
1827- //github.com/ Serializes the request to a JSON byte vector.
1828- //github.com/
1829- //github.com/ This method attempts to serialize the entire request structure into a JSON
1830- //github.com/ formatted byte vector representation.
1831- //github.com/
1832- //github.com/ # Returns
1833- //github.com/
1834- //github.com/ - `Result<Vec<u8>, serde_json::Error>` - The serialized JSON bytes on success,
1835- //github.com/ or a serialization error on failure.
1836- pub fn try_json_vec ( & self ) -> Result < Vec < u8 > , serde_json:: Error > {
1837- serde_json:: to_vec ( self )
1838- }
1839-
1840- //github.com/ Serializes the request to a JSON byte vector.
1841- //github.com/
1842- //github.com/ This method serializes the entire request structure into a JSON formatted
1843- //github.com/ byte vector representation.
1844- //github.com/
1845- //github.com/ # Returns
1846- //github.com/
1847- //github.com/ - `Vec<u8>` - The serialized JSON bytes.
1848- //github.com/
1849- //github.com/ # Panics
1850- //github.com/
1851- //github.com/ This function will panic if the serialization fails.
1852- pub fn json_vec ( & self ) -> Vec < u8 > {
1853- self . try_json_vec ( ) . unwrap ( )
1854- }
1855-
1856- //github.com/ Serializes the request to a JSON byte vector with filtered fields.
1857- //github.com/
1858- //github.com/ This method attempts to serialize the request structure into a JSON formatted
1859- //github.com/ byte vector representation, keeping only the fields that satisfy the predicate.
1860- //github.com/
1861- //github.com/ # Arguments
1862- //github.com/
1863- //github.com/ - `F: FnMut(&(&String, &mut Value)) -> bool` - A function that takes a reference to a map entry (&(&String, &mut Value)),
1864- //github.com/ returns `true` to keep the field, `false` to remove it.
1865- //github.com/
1866- //github.com/ # Returns
1867- //github.com/
1868- //github.com/ - `Result<Vec<u8>, serde_json::Error>` - The serialized JSON bytes on success,
1869- //github.com/ or a serialization error on failure.
1870- pub fn try_json_vec_filter < F > ( & self , predicate : F ) -> Result < Vec < u8 > , serde_json:: Error >
1871- where
1872- F : FnMut ( & ( & String , & mut Value ) ) -> bool ,
1873- {
1874- let mut value: Value = serde_json:: to_value ( self ) ?;
1875- if let Some ( map) = value. as_object_mut ( ) {
1876- let filtered: Map < String , Value > = map
1877- . iter_mut ( )
1878- . filter ( predicate)
1879- . map ( |( key, value) | ( key. clone ( ) , value. clone ( ) ) )
1880- . collect ( ) ;
1881- return serde_json:: to_vec ( & Value :: Object ( filtered) ) ;
1882- }
1883- serde_json:: to_vec ( & value)
1884- }
1885-
1886- //github.com/ Serializes the request to a JSON byte vector with filtered fields.
1887- //github.com/
1888- //github.com/ This method serializes the request structure into a JSON formatted byte vector
1889- //github.com/ representation, keeping only the fields that satisfy the predicate.
1890- //github.com/
1891- //github.com/ # Arguments
1892- //github.com/
1893- //github.com/ - `F: FnMut(&(&String, &mut Value)) -> bool` - A function that takes a reference to a map entry (&(&String, &mut Value)),
1894- //github.com/ returns `true` to keep the field, `false` to remove it.
1895- //github.com/
1896- //github.com/ # Returns
1897- //github.com/
1898- //github.com/ - `Vec<u8>` - The serialized JSON bytes.
1899- //github.com/
1900- //github.com/ # Panics
1901- //github.com/
1902- //github.com/ This function will panic if the serialization fails.
1903- pub fn json_vec_filter < F > ( & self , predicate : F ) -> Vec < u8 >
1904- where
1905- F : FnMut ( & ( & String , & mut Value ) ) -> bool ,
1906- {
1907- self . try_json_vec_filter ( predicate) . unwrap ( )
1908- }
1909-
1910- //github.com/ Serializes the request to a JSON string.
1911- //github.com/
1912- //github.com/ This method attempts to serialize the entire request structure into a JSON
1913- //github.com/ formatted string representation.
1914- //github.com/
1915- //github.com/ # Returns
1916- //github.com/
1917- //github.com/ - `Result<String, serde_json::Error>` - The serialized JSON string on success,
1918- //github.com/ or a serialization error on failure.
1919- pub fn try_json_string ( & self ) -> Result < String , serde_json:: Error > {
1920- serde_json:: to_string ( self )
1921- }
1922-
1923- //github.com/ Serializes the request to a JSON string.
1924- //github.com/
1925- //github.com/ This method serializes the entire request structure into a JSON formatted
1926- //github.com/ string representation.
1927- //github.com/
1928- //github.com/ # Returns
1929- //github.com/
1930- //github.com/ - `String` - The serialized JSON string.
1931- //github.com/
1932- //github.com/ # Panics
1933- //github.com/
1934- //github.com/ This function will panic if the serialization fails.
1935- pub fn json_string ( & self ) -> String {
1936- self . try_json_string ( ) . unwrap ( )
1937- }
1938-
1939- //github.com/ Serializes the request to a JSON string with filtered fields.
1940- //github.com/
1941- //github.com/ This method attempts to serialize the request structure into a JSON formatted
1942- //github.com/ string representation, keeping only the fields that satisfy the predicate.
1943- //github.com/
1944- //github.com/ # Arguments
1945- //github.com/
1946- //github.com/ - `F: FnMut(&(&String, &mut Value)) -> bool` - A function that takes a reference to a map entry (&(&String, &mut Value)),
1947- //github.com/ returns `true` to keep the field, `false` to remove it.
1948- //github.com/
1949- //github.com/ # Returns
1950- //github.com/
1951- //github.com/ - `Result<String, serde_json::Error>` - The serialized JSON string on success,
1952- //github.com/ or a serialization error on failure.
1953- pub fn try_json_string_filter < F > ( & self , predicate : F ) -> Result < String , serde_json:: Error >
1954- where
1955- F : FnMut ( & ( & String , & mut Value ) ) -> bool ,
1956- {
1957- let mut value: Value = serde_json:: to_value ( self ) ?;
1958- if let Some ( map) = value. as_object_mut ( ) {
1959- let filtered: Map < String , Value > = map
1960- . iter_mut ( )
1961- . filter ( predicate)
1962- . map ( |( key, value) | ( key. clone ( ) , value. clone ( ) ) )
1963- . collect ( ) ;
1964- return serde_json:: to_string ( & Value :: Object ( filtered) ) ;
1965- }
1966- serde_json:: to_string ( & value)
1967- }
1968-
1969- //github.com/ Serializes the request to a JSON string with filtered fields.
1970- //github.com/
1971- //github.com/ This method serializes the request structure into a JSON formatted string
1972- //github.com/ representation, keeping only the fields that satisfy the predicate.
1973- //github.com/
1974- //github.com/ # Arguments
1975- //github.com/
1976- //github.com/ - `FnMut(&(&String, &mut Value)) -> bool` - A function that takes a reference to a map entry (&(&String, &mut Value)),
1977- //github.com/ returns `true` to keep the field, `false` to remove it.
1978- //github.com/
1979- //github.com/ # Returns
1980- //github.com/
1981- //github.com/ - `String` - The serialized JSON string.
1982- //github.com/
1983- //github.com/ # Panics
1984- //github.com/
1985- //github.com/ This function will panic if the serialization fails.
1986- pub fn json_string_filter < F > ( & self , predicate : F ) -> String
1987- where
1988- F : FnMut ( & ( & String , & mut Value ) ) -> bool ,
1989- {
1990- self . try_json_string_filter ( predicate) . unwrap ( )
1991- }
19921826}
0 commit comments