Repository: nushell/nushell
File: crates/nu-command/src/formats/to/text.rs (Rust)

Code before:
    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let span = call.head;
        let no_newline = call.has_flag(engine_state, stack, "no-newline")?;
        let input = input.try_expand_range()?;
        let config = stack.get_config(engine_state);

        match input {
            PipelineData::Empty => Ok(Value::string(String::new(), span)
                .into_pipeline_data_with_metadata(update_metadata(None))),
            PipelineData::Value(value, ..) => {
                let value_type = value.clone().get_type();
                let mut str = local_into_string(value, LINE_ENDING, &config);
                let str = if matches!(value_type, Type::List(_) | Type::Record(_)) {
                    if !no_newline {
                        str.push_str(LINE_ENDING);
                    }
                    str
                } else {
                    str
                };
                Ok(
                    Value::string(str, span)
                        .into_pipeline_data_with_metadata(update_metadata(None)),
                )
            }
            PipelineData::ListStream(stream, meta) => {
                let span = stream.span();
                let iter = stream.into_inner().map(move |value| {
                    let mut str = local_into_string(value, LINE_ENDING, &config);
                    if !no_newline {
                        str.push_str(LINE_ENDING);
                    }
                    str
                });
                Ok(PipelineData::ByteStream(
                    ByteStream::from_iter(
                        iter,
                        span,
                        engine_state.signals().clone(),
                        ByteStreamType::String,
                    ),
                    update_metadata(meta),
                ))
            }
            PipelineData::ByteStream(stream, meta) => {

Review comment (suggestion):
Thanks, yeah this is what I had in mind. Although, it's possible to make it a little simpler.

```suggestion
                let is_compound_type = matches!(value, Value::List { .. } | Value::Record { .. });
                let mut str = local_into_string(value, LINE_ENDING, &config);
                if is_compund_type && !no_newline {
                    str.push_str(LINE_ENDING);
                }
```

Code after:
    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        let span = call.head;
        let no_newline = call.has_flag(engine_state, stack, "no-newline")?;
        let input = input.try_expand_range()?;
        let config = stack.get_config(engine_state);

        match input {
            PipelineData::Empty => Ok(Value::string(String::new(), span)
                .into_pipeline_data_with_metadata(update_metadata(None))),
            PipelineData::Value(value, ..) => {
                let is_compound_type = matches!(value, Value::List { .. } | Value::Record { .. });
                let mut str = local_into_string(value, LINE_ENDING, &config);
                if is_compound_type && !no_newline {
                    str.push_str(LINE_ENDING);
                }

                Ok(
                    Value::string(str, span)
                        .into_pipeline_data_with_metadata(update_metadata(None)),
                )
            }
            PipelineData::ListStream(stream, meta) => {
                let span = stream.span();
                let iter = stream.into_inner().map(move |value| {
                    let mut str = local_into_string(value, LINE_ENDING, &config);
                    if !no_newline {
                        str.push_str(LINE_ENDING);
                    }
                    str
                });
                Ok(PipelineData::ByteStream(
                    ByteStream::from_iter(
                        iter,
                        span,
                        engine_state.signals().clone(),
                        ByteStreamType::String,
                    ),
                    update_metadata(meta),
                ))
            }
            PipelineData::ByteStream(stream, meta) => {
                Ok(PipelineData::ByteStream(stream, update_metadata(meta)))
            }
        }
    }